Subject: toolchain/18763: rpcgen expands macros that should be preserved
To: None <>
From: None <>
List: netbsd-bugs
Date: 10/22/2002 13:38:17
>Number:         18763
>Category:       toolchain
>Synopsis:       rpcgen expands macros that should be preserved
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Oct 22 04:39:00 PDT 2002
>Originator:     Andreas Johansson
>Release:        NetBSD 1.6
Rockstorm Technology AB
System: NetBSD bmw 1.6 NetBSD 1.6 (GENERIC) #0: Sun Sep 8 19:43:40 UTC 2002 i386
Architecture: i386
Machine: i386
rpcgen expands some macros built into cpp that should be passed on to the
output file. rpcgen doesn't really do any replacing, but it calls cpp in
order to evaluate #ifdef RPC_HDR statements and such, and it the process
some predefined macros gets expanded by cpp.

The macro I've been bitten by is __STDC__ which is replaced by '1', but I'm
sure this is not the only potential problem. Interrestingly, cpp -dM doesn't
even report that __STDC__ is defined. It can be undefined by cpp -U __STDC__,
but this always gives me a warning.
cd src/include/rpc
rpcgen -C -h rpcb_prot.x

Line 171 in rpcb_prot.x:

%#if __STDC__
%extern  bool_t xdr_rpcblist(XDR *, rpcblist**);
%#else /* K&R C */
%bool_t xdr_rpcblist();

will be replaced with:

#if 1
extern  bool_t xdr_rpcblist(XDR *, rpcblist**);
#else /* K&R C */
bool_t xdr_rpcblist();

This doesn't really break anything as long as you compile with a standard
compiler, but it works only because __STDC__ was tested with #if. In
previous versions of NetBSD, it was tested with #ifdef, and this makes old
code uncompilable with a new toolchain (this is my real problem).

Maybe an option to cpp not to expand any macros (i.e. only respond to lines
that starts with '#'), and use this option in rpcgen?

The -undef option of cpp does not undefine __STDC__, so this option can't
solve the problem by itself. cpp -undef -U __STDC__ -U ... could be a fix,
but this leads to annoying warnings.