ANSI vs K&R 3.7.1 structures Help!
john c kelly
jkelly at world.std.com
Sat Mar 23 04:37:21 AEST 1991
Sorry to bother everyone but I am about to port a fair size
application from one machine to another. I had not done much work
on the target machine so I decided to checkout the compiler's
capabilities. I took a copy of the C torture tests and tried to
compile the code on the new machine. I could not do the testing
myself, the system administrator had to, so I placed all of the
code into one single file and he ran the compiler, which promptly
died. The sysadmin put in a service call and sent a copy of the
code to the engineers and they replied:
This note is to explain why we do not think that the
test case code is a valid ANSI C program. Please note we
only support the K&R standard where it agrees with ANSI.
In ANSI 3.7.1, 5th paragraph of the 'Contraints'
section, it states: 'If the declarator includes an
identifier list, each declaration in the declaration list
shall have at least one declarator, and those declarators
shall declare only identifiers from the identifier list.'
The key point is that each function must have a
declarator.
In function s22(pd0) you declared a structure :
struct defs {
... some stuff
... some more stuff
}; /* <--- should be a declarator here. */
struct defs *pd0;
The problem with your code is that the 'struct defs'
statement does not have a declarator. The compiler
dosen't like the semi-colon because it is expecting an
identifier for the declarator.
The following is what the ANSI version of the above
code looks like:
struct defs {
... some stuff
... some more stuff
} *pd0; /* <--- now the declaration has a declarator. */
We converted the test case to ANSI format, and got
further compile errors becasue the compiler gives the
definition of 'struct defs' tag in function s22 file
scope, and so each subsequent declaration of 'struct
defs' receives an error message that stuct tags cannot be
redefined. The way to resolve that is to only do one
defintion of the 'struct defs' tag.
HELP! I am highly suspicious of their response. I have used
this stye of code before. In fact the code compiles fine using 5
other compilers! I don't have the ANSI spec to quote from so I
appeal to the C-NET-GODS to tell me if they are blowing smoke or I
am just stupid. One thing that really wories me is that they say
the 'stuct defs' tag has been given file scope. It was declared
INSIDE the function! I thought that this made it local not global.
ANY help or suggstions would be greatly appreciated. If
possible e-mail directly to me I'll summarize if enough interest.
John C. Kelly MaBell: 717-986-5038
Prime System Integration (prefered)--> Prime: j.kelly at md-b.prime.com
Prime Computer Inc. Client: ampt0659 at s2901b.amp.com
DISCLAIMER: I speak for me. Only. Home: jkelly at world.std.com
"You can demonstrate a program for an executive - but you can't make
him computer literate."
--
John C. Kelly MaBell: 717-986-5038
Prime System Integration Prime: j.kelly at md-b.prime.com
Prime Computer Inc. Client: ampt0659 at s2901b.amp.com
More information about the Comp.std.c
mailing list