This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Switching 'cast to union' off?


On Fri, 17 Mar 2000, Martin v. Loewis wrote:

> I've been trying to come up with an example that presents your
> problem, but I can't create one. Do have code that produces a certain
> warning and want an option to turn the warning off, or do you have
> code that does not produce a warning, and you want to get one? In any
> case: what is the code?

We have code that does _not_ produce a warning, but we rather want a
warning produced.

Example code:

----------------------------------
typedef union { long n; } SCM;

int main()
{
    SCM x;
    long y;

    x = (SCM)y;   /* This is a misuse of type SCM (also, not allowed by
                  /* ANSI).  However, the compiler accepts it. */

    return 0;
}
----------------------------------

I tried egcs-2.91.66 (Suse 6.3 linux) and gcc 2.95.2 (solaris 7).  Both
show the same behaviour.  Compiler options were:  gcc -Wall test.c
With gcc -Wall -pedantic test.c we get:
  test.c: In function `main':
  test.c:8: warning: ANSI C forbids casts to union type
However, -pedantic also reports lots of other ansi violations that are not
of importance for us (like use of asm commands).  Thus, we don't want to
require users to have to enable -pedantic to find the casting problem
described above.

In general, I think, it would be nice to be able to switch of each of the
GNU extensions by compiler options separately.

Thanks for your answer!  Sorry that my description was not clear.

Dirk Herrmann


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]