gpc 20070904, based on gcc-3.4.5 (mingw special)
I got a compilation error, "type mismatch", when I passed a string literal to a routine with a formal parameter of "const var s : string". In tests, this had been acceptable to the compiler. I find that whether it is acceptable seems to be a function of whether the call is preceded by another call (to a different routine), passing a string literal to (as?) a "const s : string" formal parameter.
jsm1bad.pas gets a "type mismatch" compilation error. jsm1ok.pas compiles, links, and executes.
On 25 Jun 2012 at 22:18, Jay Michael wrote:
gpc 20070904, based on gcc-3.4.5 (mingw special)
I got a compilation error, "type mismatch", when I passed a string
literal to a routine with a formal parameter of "const var s : string". In tests, this had been acceptable to the compiler. I find that whether it is acceptable seems to be a function of whether the call is preceded by another call (to a different routine), passing a string literal to (as?) a "const s : string" formal parameter.
jsm1bad.pas gets a "type mismatch" compilation error. jsm1ok.pas compiles, links, and executes.
Maybe it is just me - but I don't know what a "const var" is. I do know about these:
s : string var s : string const s : string
To me, "const var s : string" is a syntax error. This seems like a relic from certain other programming languages ...
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Is what is meant here "protected var s : string"?
Best regards, Bastiaan.
On Jun 27, 2012, at 8:40 AM, Prof A Olowofoyeku (The African Chief) wrote:
On 25 Jun 2012 at 22:18, Jay Michael wrote:
gpc 20070904, based on gcc-3.4.5 (mingw special)
I got a compilation error, "type mismatch", when I passed a string
literal to a routine with a formal parameter of "const var s : string". In tests, this had been acceptable to the compiler. I find that whether it is acceptable seems to be a function of whether the call is preceded by another call (to a different routine), passing a string literal to (as?) a "const s : string" formal parameter.
jsm1bad.pas gets a "type mismatch" compilation error. jsm1ok.pas compiles, links, and executes.
Maybe it is just me - but I don't know what a "const var" is. I do know about these:
s : string var s : string const s : string
To me, "const var s : string" is a syntax error. This seems like a relic from certain other programming languages ...
Best regards, The Chief
Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Gpc mailing list Gpc@gnu.de https://www.g-n-u.de/mailman/listinfo/gpc
Jay Michael wrote:
gpc 20070904, based on gcc-3.4.5 (mingw special)
{ passing string literal to const var string formal parameter } { produces } { error: type mismatch in argument 1 of `rejecter' } { unless have previous call (to another routine) passing string } { literal to const string }
const var parameters were introduced to interface with external (C) routines where (1) the API requires that the parameter is passed by reference and (2) passing a constant as actual parameter should be allowed. For normal use, const parameters can be used.
Regards,
Adriaan van Os
On 27 Jun 2012 at 11:47, Adriaan van Os wrote:
[...]
const var parameters were introduced to interface with external (C) routines where (1) the API requires that the parameter is passed by reference and (2) passing a constant as actual parameter should be allowed. For normal use, const parameters can be used.
Don't const parameters comply with both conditions?
Best regards, The Chief ------- Prof. Abimbola Olowofoyeku (The African Chief) Web: http://www.greatchief.plus.com
Prof. A Olowofoyeku (The African Chief) wrote:
On 27 Jun 2012 at 11:47, Adriaan van Os wrote:
[...]
const var parameters were introduced to interface with external (C) routines where (1) the API requires that the parameter is passed by reference and (2) passing a constant as actual parameter should be allowed. For normal use, const parameters can be used.
Don't const parameters comply with both conditions?
No, with const parameters, the compiler decides what is more efficient, by reference or by value. For small sized parameters, by reference is more efficient. So, an integer const (and probably a real const) parameter will be passed by value, which could conflict with the ABI of an external (C) routine.
Regards,
Adriaan van Os
Prof. A Olowofoyeku (The African Chief) wrote:
On 27 Jun 2012 at 11:47, Adriaan van Os wrote:
[...]
const var parameters were introduced to interface with external (C) routines where (1) the API requires that the parameter is passed by reference and (2) passing a constant as actual parameter should be allowed. For normal use, const parameters can be used.
Don't const parameters comply with both conditions?
No, with const parameters, the compiler decides what is more efficient, by reference or by value. For small sized parameters, by reference is more efficient. So, an integer const (and probably a real const) parameter will be passed by value, which could conflict with the ABI of an external (C) routine.
Of course, I intended to say "For small sized parameters, by value is more efficient."
Regards,
Adriaan van Os
The attached patch should fix the problem.
On 28 Jun 2012 at 19:58, Waldek Hebisch wrote:
The attached patch should fix the problem.
Do you have your latest sources in a repository? The patch seems to be a patch for a version of the source code that is not on your GPC page.
Thanks.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
On 28 Jun 2012 at 19:58, Waldek Hebisch wrote:
The attached patch should fix the problem.
Do you have your latest sources in a repository? The patch seems to be a patch for a version of the source code that is not on your GPC page.
See:
https://github.com/hebisch/gpc
On 24 Jul 2012 at 21:38, Waldek Hebisch wrote:
On 28 Jun 2012 at 19:58, Waldek Hebisch wrote:
The attached patch should fix the problem.
Do you have your latest sources in a repository? The patch seems to be a patch for a version of the source code that is not on your GPC page.
See:
Many thanks.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/