Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug (?) in gcc-2.2.2's preprocessor

0 views
Skip to first unread message

Alexandre Oliva

unread,
Oct 4, 1992, 10:09:38 PM10/4/92
to
I am using gcc 2.2.2 in a SPARC Station running SunOS 4.1.1, writing a
program which needs some ioctl commands for magnetic tape control.

When I use the system's C compiler, the program works. When I use gcc,
or even g++ (I began writing it in C++), it does not work any more.

I found the reason. The constant MTIOCGET, which is defined in a
system include file, is understood differently by gcc's cpp and Sun's
cpp.

in /usr/include/sys/mtio.h, there is this line:

#define MTIOCGET _IOR(m, 2, struct mtget) /* get tape status */

and in /usr/include/sys/ioccom.h, there is this line:

#define _IOR(x,y,t) (_IOC_OUT|((sizeof(t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)

I noticed that Sun's cpp changes the 'x' to 'm', but gcc's does not.
Which one is correct? What can I do to fix the problem, so that I can
be sure my program can by compiled in other Unix systems?

Thanks in advance.

Alexandre Oliva
ol...@dcc.unicamp.br
Depto de Ciencia da Computacao
DCC - IMECC - UNICAMP
Campinas SP Brazil

Fergus James HENDERSON

unread,
Oct 5, 1992, 6:52:38 AM10/5/92
to
ol...@dcc.unicamp.br (Alexandre Oliva) writes:

>When I use the system's C compiler, the program works. When I use gcc,
>or even g++ (I began writing it in C++), it does not work any more.

[...]


>and in /usr/include/sys/ioccom.h, there is this line:
>
>#define _IOR(x,y,t) (_IOC_OUT|((sizeof(t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)
>
>I noticed that Sun's cpp changes the 'x' to 'm', but gcc's does not.
>Which one is correct? What can I do to fix the problem, so that I can
>be sure my program can by compiled in other Unix systems?

This is not a bug in gcc - gcc is following the ANSI standard here -
but instead it is a difference between ANSI C and traditional K&R C.
If you compile with -traditional, then gcc's preprocessor will
behave like Sun's.

PS. If you had compiled with -Wtraditional, gcc would have told you this
itself. I would strongly suggest that everyone compiles with all warnings
enabled unless there is a good reason to avoid this. By "all warnings",
I mean something like the following:
gcc -O -ansi -pedantic -Wall -Wshadow -Wwrite-strings -Wid-clash-31 \
-Wpointer-arith -Wcast-qual -Wtraditional -Wcast-align

--
Fergus Henderson f...@munta.cs.mu.OZ.AU
This .signature virus is a self-referential statement that is true - but
you will only be able to consistently believe it if you copy it to your own
.signature file!

0 new messages