Diagnostics (continued)

J

jacob navia

Consider this nice C program:

short long n;
signed unsigned b;
const long const long a;
unsigned double w;
signed float k;
short double q;
unsigned long double z;

I was astonished that my dear lcc-win very bad diagnostic messages
wrote for those errors.

After correcting that, I passed this code through MSVC and it
wrote a correct diagnostic for all of those errors... excepting
the last.

unsigned long double is legal?

I have serious doubts.

Besides, MSVC emitted just a warning for repeated qualifiers like
"const long const long"... Isn't that an error?

gcc wrote correct diagnostics for all of them, and all were errors,
not warnings.

PellesC missed "const long const long" completely, but the errors
were as I had it: just "Invalid type specification" instead of a
more specific error.
 
K

Keith Thompson

jacob navia said:
Consider this nice C program:

short long n;
signed unsigned b;
const long const long a;
unsigned double w;
signed float k;
short double q;
unsigned long double z;

I was astonished that my dear lcc-win very bad diagnostic messages
wrote for those errors.

After correcting that, I passed this code through MSVC and it
wrote a correct diagnostic for all of those errors... excepting
the last.

unsigned long double is legal?

I have serious doubts.

No, ``unsigned long double'' is a constraint violation, as you can
verify by re-reading C99 6.7.2, Type specifiers.
Besides, MSVC emitted just a warning for repeated qualifiers like
"const long const long"... Isn't that an error?

No, type *specifiers* may not be repeated (other than "long long" and
variations), but type *qualifiers* such as "const" may be repeated, so
"const long const long" is equivalent to "const long long". (It's
ugly, though, so a warning seems appropriate, though it's not
required.)

C99 6.7.3p4:

If the same qualifier appears more than once in the same
_specifier-qualifier-list_, either directly or via one or more
typedefs, the behavior is the same as if it appeared only once.

The idea, I think, is that if you have a typedef for "const int", you
can still apply "const" to the typedef:

typedef const int c_int;
const c_int x = 42;

(IMHO "const" belongs on the object declaration, not buried in a
typedef, but the language allows it.)

In any case, as you know, the standard doesn't distinguish between
errors and warnings. A warning that doesn't cause translation to fail
can still be a valid "diagnostic message" as required by the standard.
gcc wrote correct diagnostics for all of them, and all were errors,
not warnings.

Ok, but many of gcc's required diagnostic are warnings.
PellesC missed "const long const long" completely,

Probably because it's valid.
but the errors
were as I had it: just "Invalid type specification" instead of a
more specific error.

I don't feel strongly that a more specific error message is necessary,
but that's up to you.
 
L

lawrence.jones

Keith Thompson said:
(IMHO "const" belongs on the object declaration, not buried in a
typedef, but the language allows it.)

And, as I recall, one of the key arguments for allowing redundant
qualifiers in C99 was that sig_atomic_t is allowed to be a volatile
qualified type and without allowing redundant qualifiers there was no
portable way to declare an object of that type that was *guaranteed* to
be volatile.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top