🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Alexandre Oliva Mon, 05 Oct 1992 02:09
Bug (?) in gcc-2.2.2's preprocessor
#1252
Author: Alexandre Oliva
Date: Mon, 05 Oct 1992 02:09
29 lines
1410 bytes
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
oliva@dcc.unicamp.br
Depto de Ciencia da Computacao
DCC - IMECC - UNICAMP
Campinas SP Brazil
Re: Bug (?) in gcc-2.2.2's preprocessor
#1257
Author: Fergus James HENDERSON
Date: Mon, 05 Oct 1992 10:52
30 lines
1956 bytes
oliva@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             fjh@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!
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads