Break'em good and hard...

P

Phil Carmody

Purely recreationally...

I'm just wondering what people can come up with as a small,
say sig-length, example of pedantically correct C code which
will fail in as many different C compilers as possible, the
more common the better, the more thorough the breakage the
better, and with bonus points if those compilers are stuck
into standards compliance mode. Failure may be either run-
time or compile time.

Reclaim the name space!

Phil
 
J

James Kuyper

Kelsey said:
/* save as file.c */
#include "file.c"

That doesn't qualify as "pedantically correct". It has more than "15
nesting levels for #included files". (5.2.4.1p1).
 
J

James Kuyper

Phil said:
Purely recreationally...

I'm just wondering what people can come up with as a small,
say sig-length, example of pedantically correct C code which
will fail in as many different C compilers as possible, the
more common the better, the more thorough the breakage the
better, and with bonus points if those compilers are stuck
into standards compliance mode. Failure may be either run-
time or compile time.

Reclaim the name space!

Phil

#error This program is pedantically correct.
 
P

Phil Carmody

James Kuyper said:
#error This program is pedantically correct.

If the only breakage you can think of is #error, then your
imagination's not running wild enough!

Phil
 
J

James Kuyper

Phil said:
If the only breakage you can think of is #error, then your
imagination's not running wild enough!

True - that's the only way I can imagine to combine "pedantically
correct" and "fail ... [in] standards compliance mode"; with that
exception, those two categories seem to me to be otherwise, by
definition, mutually exclusive. This implies you're using different
definitions than I am.

I've been waiting for a decent example of what you're talking about, but
Kelsey Bjarnason's contribution was pedantically incorrect. Neither of
pete's contributions fail, at least, not with my compiler, and I can't
imagine why he'd expect them to fail on any other compiler, either.
Possibly I'm missing some point that seems subtle now, but which will be
blindingly obvious when someone points it out, which is why I hadn't
commented on that till now.

Maybe you mean "fail" in some different sense?:

#include <stdlib.h>
int main(void) {return EXIT_FAILURE;}
 
P

Phil Carmody

James Kuyper said:
Phil said:
If the only breakage you can think of is #error, then your
imagination's not running wild enough!

True - that's the only way I can imagine to combine "pedantically
correct" and "fail ... [in] standards compliance mode"; with that
exception, those two categories seem to me to be otherwise, by
definition, mutually exclusive. This implies you're using different
definitions than I am.
I've been waiting for a decent example of what you're talking about,

Here's a rubbish example which breaks gcc in not-really-C mode (and
of course additionally exercises it in C99 mode) on my home machine:

int main(int asm, char**restrict)
{
int linux=asm, unix=**restrict;
return linux*unix;
}

It fails to break gcc in C89 mode. Looking at -dM in the two standard
modes, it seems that gcc has cleaned up its act in the last few years.

Phil
 
J

James Kuyper

Phil said:
James Kuyper said:
Phil said:
Phil Carmody wrote:
Purely recreationally...

I'm just wondering what people can come up with as a small,
say sig-length, example of pedantically correct C code which will
fail in as many different C compilers as possible, the more common
the better, the more thorough the breakage the better, and with
bonus points if those compilers are stuck into standards compliance
mode. Failure may be either run-
time or compile time.

Reclaim the name space!

Phil
#error This program is pedantically correct.
If the only breakage you can think of is #error, then your
imagination's not running wild enough!
True - that's the only way I can imagine to combine "pedantically
correct" and "fail ... [in] standards compliance mode"; with that
exception, those two categories seem to me to be otherwise, by
definition, mutually exclusive. This implies you're using different
definitions than I am.
I've been waiting for a decent example of what you're talking about,

Here's a rubbish example which breaks gcc in not-really-C mode (and
of course additionally exercises it in C99 mode) on my home machine:

int main(int asm, char**restrict)
{
int linux=asm, unix=**restrict;
return linux*unix;
}

It fails to break gcc in C89 mode. Looking at -dM in the two standard
modes, it seems that gcc has cleaned up its act in the last few years.

It's trivial to write pedantically correct code that breaks on any
particular non-conforming compiler; and it's just a lot of pointless
work to put together a piece of code that maximizes the number of
different non-conforming compilers that it will break on.

It's your desire to find such code that will break on a conforming
compiler that confuses me.

It's actually straightforward to do so; every implementation has limits
in addition to the ones listed in 5.2.4.1p1. It's entirely feasible to
write code which exceeds none of those limits, but exceeds any
particular implementation's capacity to translate.

However, you specified that the program should be "small, say
sig-length", and I can't figure out any way to do so within those space
limits.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top