Can I initial a static global variable by calling a function in C language? -


Can I start a stable global variable by calling a function in C language? For example:

  Fixed int var_01 = funny ();  

When I use it in VC6, it succeeds. But it failed in GCC 4.6.1. it's so weird. I think this experiment is illegal in C89? Or is the reason for this reason?

In C99 and as far as I know in C89 draft C99 standard section 6.7 .8 Start :

An object with a static storage period from the draft must be either a continuous expression or string literal.

All expressions in the initialization for the constant frequency object will be constant expressions or string literals.

>

When they are contained within a subexpression that has not been evaluated. 9 8)

Both GCC generates the same error using -std = c99 and -std = C89 , notice that I am using the following flag -Wall -Wextra -pedantic .

This version of the Visual Studio compiler does not work in C ( ) in modern versions, but it works in C ++. That's why you may be compiling it in Visual Studio as C ++.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -