Nim Nuggets: Nim talk at Strange Loop 2021

max haughton maxhaton at gmail.com
Sun Oct 17 23:06:12 UTC 2021


On Sunday, 17 October 2021 at 22:53:29 UTC, Walter Bright wrote:
> On 10/17/2021 2:11 PM, max haughton wrote:
>> On Sunday, 17 October 2021 at 19:18:25 UTC, Walter Bright 
>> wrote:
>>> [...]
>> 
>> https://gcc.godbolt.org/z/jr5W6rY1W
>> 
>> If I read you correctly, gcc circa '06 could do what you 
>> describe. Or do you mean in windows land?
>
> ------------------------
> mercury> cat test.c
> int square(int x) { return x * x; }
>
> const int c = square(2);
>
> mercury> cc test.c -O3
> test.c:3:1: error: initializer element is not constant
>  const int c = square(2);
>  ^
> mercury> cc test.c --version
> cc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
> Copyright (C) 2013 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  
> There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A 
> PARTICULAR PURPOSE.
> -------------------------
>
> Your example is fundamentally different:
>
> -------------------------
> int square(int x) { return x * x; }
>
> int main()
> {
>     const int s = square(2);  <== not a constant-expression
>     return s;
>
>
> }
> ----------------

I see. I thought you meant the constant-folding power rather than 
initializing something static.

"The manner and timing of static initialization" is listed as 
unspecified behaviour in the C11 standard, it's curious why this 
restriction persists.


More information about the Digitalmars-d mailing list