bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in C compiler Compiler Bug for Case 3411658RE (fwd)


From: Paul Eggert
Subject: Re: Bug in C compiler Compiler Bug for Case 3411658RE (fwd)
Date: 28 Apr 2003 13:56:18 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

[Martin, can you please forward this message to HP support?  Thanks.]

> From: "Belgardt, Wolfgang" <address@hidden>
> Date: Mon, 28 Apr 2003 16:19:28 +0200

> The construct at hand involves an initializer for an
> object with static storage duration, so it is a
> constraint that the expression be a constant expression
> or a string literal.  Since it isn't a string literal,
> it must be one of the "relaxed" forms of constant
> expression enumerated in 6.6(7).  (_Bool)&foo is clearly
> not a null pointer constant, an address constant, or
> an address constant for an object type plus or minus
> an integer constant expression.

There must be some confusion here, due to later discussion on the
subject.  Let's go back to an extract from the original program that
started this thread:

  #include <stdbool.h>
  struct s { _Bool s: 1; _Bool t; } s;
  bool e = &s;

There is no cast here, and the expression "&s" is clearly a constant
expression, so it is valid C99.

> Since the address of an object with static storage duration is not
> known until link time, producing the correct result requires that
> the compare operation happen at link time or later.

Not in this case, since &s cannot possibly be zero.

> a compiler could simply evaluate the expression as 1 without
> requiring any link-time or run-time evaluation.

Yes, that's correct.

> However, in the realm of practical considerations, it should be
> noted that it is a common practice on some platforms to use weak
> symbol references

Such practice is beyond the scope of the C99 standard.  Weak symbols
are an extension to C99, and C99 compilers that support them as
extensions can place extra restrictions on them.

In other words, a C99 compiler can prohibit "bool e = &s;" if "s" is a
weak symbol reference, without violating the C99 standard, since one
cannot declare a weak symbol in pure C99.  However, the program
fragment quoted above must be accepted by any valid C99 compiler.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]