Re: Not STD C is "not C" ? ----WAS: Re: C to Java Byte Code
In article <Bltgd.6$304.0@ trndny06> "Thomas G. Marshall" <tgm2tothe10thp ower@replacetex twithnumber.hot mail.com> writes:
....[color=blue]
> I don't see i=i++ as ever anything useful, but 45° tangental to this
> original thread is something that bothers me. There is a *prevailing*
> notion that:
> If it ain't standard C, it ain't C
> which I think is not quite true.[/color]
In this groups it is true. The aim in this group is portable C. If your
programming is platform sepcific you better ask in a newsgroup related to
your platform.
[color=blue]
> It's important because there are
> many things that cannot be written in standard C that are nonetheless useful
> to write in non-std C:
>
> Device Drivers (usually)
> malloc()
> Anything embedded that needs to tweek memory
> mapped registers[/color]
Indeed, they can not be written in standard C as the code is necesarily
very platform specific. So a newsgroup related to your platform is a
better place to ask.
[color=blue]
> This issue was raised to my attention recently when I was educated by many
> here on what the standard actually allows. But knowing the standard, IMHO,
> isn't the bottom line. Knowing the "usual" rules of C, particularly the
> /likely/ behavior of something undefined or platform dependent in the spec,
> is, particularly if you're recruiting.[/color]
But what is likely behaviour? How do you define that? The only behaviour
that is likely about "i = i++;" is that it probably will set "i" to either
the value before the statement or to the incremented value. And that is
not very useful information either.
And that is what happens in most cases of undefined behaviour, it can do
one thing or something else, and most likely both can occur on different
platforms, or sometimes on the same platform with different compilers,
or sometimes on the same platform with different generations of the same
compiler.
I once got a program that crashed reliably on the platform where I wished
to use it. The culprit was a snippet of code that assumed that pointers
to character were plain long ints. So it contained the following code:
char *c, *c1;
c = malloc(sizeof(d ouble) * 2);
/* get a double aligned pointer in the array */
c1 = (char *)((long int)(c + sizeof(double) - 1) & ~(sizeof(double ) - 1));
the crash occurred when c1 was used. Not only was the code misguided
(malloc returns a pointer suitably aligned), it was also totally wrong
on that platform, because c1 pointed to c[7], which was not suitably
aligned.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
In article <Bltgd.6$304.0@ trndny06> "Thomas G. Marshall" <tgm2tothe10thp ower@replacetex twithnumber.hot mail.com> writes:
....[color=blue]
> I don't see i=i++ as ever anything useful, but 45° tangental to this
> original thread is something that bothers me. There is a *prevailing*
> notion that:
> If it ain't standard C, it ain't C
> which I think is not quite true.[/color]
In this groups it is true. The aim in this group is portable C. If your
programming is platform sepcific you better ask in a newsgroup related to
your platform.
[color=blue]
> It's important because there are
> many things that cannot be written in standard C that are nonetheless useful
> to write in non-std C:
>
> Device Drivers (usually)
> malloc()
> Anything embedded that needs to tweek memory
> mapped registers[/color]
Indeed, they can not be written in standard C as the code is necesarily
very platform specific. So a newsgroup related to your platform is a
better place to ask.
[color=blue]
> This issue was raised to my attention recently when I was educated by many
> here on what the standard actually allows. But knowing the standard, IMHO,
> isn't the bottom line. Knowing the "usual" rules of C, particularly the
> /likely/ behavior of something undefined or platform dependent in the spec,
> is, particularly if you're recruiting.[/color]
But what is likely behaviour? How do you define that? The only behaviour
that is likely about "i = i++;" is that it probably will set "i" to either
the value before the statement or to the incremented value. And that is
not very useful information either.
And that is what happens in most cases of undefined behaviour, it can do
one thing or something else, and most likely both can occur on different
platforms, or sometimes on the same platform with different compilers,
or sometimes on the same platform with different generations of the same
compiler.
I once got a program that crashed reliably on the platform where I wished
to use it. The culprit was a snippet of code that assumed that pointers
to character were plain long ints. So it contained the following code:
char *c, *c1;
c = malloc(sizeof(d ouble) * 2);
/* get a double aligned pointer in the array */
c1 = (char *)((long int)(c + sizeof(double) - 1) & ~(sizeof(double ) - 1));
the crash occurred when c1 was used. Not only was the code misguided
(malloc returns a pointer suitably aligned), it was also totally wrong
on that platform, because c1 pointed to c[7], which was not suitably
aligned.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Comment