Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2017-10

const param documentation

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin

https://www.freepascal.org/docs-html/current/ref/refsu67.html#x179-20100014.4.4

Just came to notice something....

But first: I had been under the impression, that if you
- define a param as const
- pass a global variable
- violate the contract, by modifying the global var while in the scope of the const param
then you have written invalid code, and should expect the behaviour of such code to be undefined.

On the link above it gives an example of such a situation (changing the content of  a string).
The example shows the current implemented behaviour. (the new value is assigned to the const param, and the new value is used).

The documentation states: "This behaviour is by design"

That means according to the doc, such use of a constant param has a defined and documented behaviour, and is a valid use case?

Should it not document, that it may print either value, or crash, or do something else?
Meaning "By design this code is invalid, and has no defined behaviour"

Reply by email

Michael Van Canneyt
to Martin
Martin wrote 25 lines
https://www.freepascal.org/docs-html/current/ref/refsu67.html#x179-20100014.4.4 Just came to notice something.... But first: I had been under the impression, that if you - define a param as const - pass a global variable - violate the contract, by modifying the global var while in the scope of the const param then you have written invalid code, and should expect the behaviour of such code to be undefined. On the link above it gives an example of such a situation (changing the content of  a string). The example shows the current implemented behaviour. (the new value is assigned to the const param, and the new value is used). The documentation states: "This behaviour is by design" That means according to the doc, such use of a constant param has a defined and documented behaviour, and is a valid use case? Should it not document, that it may print either value, or crash, or do something else? Meaning "By design this code is invalid, and has no defined behaviour"

What is meant is that the behaviour of the compiler is by design.

I will change the wording.

Michael.

Reply by email