C89: Compile-time constant required for initialiser?

  • Thread starter Tomás Ó hÉilidhe
  • Start date
F

Flash Gordon

Tomás Ó hÉilidhe wrote, On 12/12/07 20:31:
If I am *not* to assume that the implementation's standard library is free
from errors, then I may as well drop a boat-load of other assumptions that
I make in life, such as whether something will fall downward or upwards if
I let go of it, or whether my right arm will move if I will it to move.

Actually, you are more likely to be correct if you assume that there is
at least one bug in your implementation's standard library than if you
assume it is free from errors. You are also likely to be correct if you
assume when your SW does not work that it is a bug in your code than if
you assume it is a bug in the library.
If a particular implementor wants to use #include_green_lava in its header
files then let it... I just don't want to get errors or warnings about code
which is:

a) Not mine
b) Assumed to be perfect by the code which calls it

I use 'gcc -ansi -pedantic -Wall -Wextra' and don't get any warnings on
the system headers.
 
C

CBFalconer

Richard said:
.... snip - following quotation restored ...
But the stdio.h mainly has to match the system, not gcc. Gcc
uses dozens of different stdio.h files on different platforms.
The problem must be specific to some particular gcc/platform
combination, such as gcc + glibc for Linux.

Please don't remove attributions for quoted material.

I have also restored a sentence from my original message that you
snipped. It claims a misinstallationm, i.e. there is a mismatch
between the system, library, include files, etc. This is an
entirely different message from the one that you snipped it down
to. Normal and proper installation will have conditionals in
stdio.h that tailor it to the options, conditions, etc. in effect.
 
D

David Thompson

Is that to say that static variables within functions get exactly the same
treatment as global variables when it comes to initialisation?
Yes.

That is to > say, should I C89 compiler reject the following?:


void Func(void)
{
static int a = (0,2);
}

(I use the comma operator so as not to yield a compile-time constant).

Well, it _can_. That is not a constant expression as specified by the
standard. However, C90 6.4 or C99 6.6p10 "An implementation may accept
other forms of constant expressions." and this is an easy one to add
-- in fact it may be easier for the compiler (writer) to accept it
(with context-independent constant-folding code) than reject it.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top