Re: Puzzling program
- From: Army1987 <army1987@xxxxxxxxx>
- Date: Sat, 11 Aug 2007 11:58:59 +0200
On Fri, 10 Aug 2007 12:11:52 -0700, Keith Thompson wrote:
Even a newline at the end of the output wouldn't hurt.Well, this may be more a case of "we're only coding for one specific
platform, and don't care about portability". (Not that that's
necessarily a good thing, but at least the code becomes "system
specific behavior" rather than "errors". Of course, what happens
when they decided to port to a similar, but 64-bit, platform?)
Here's the original program:
void main()
{
char *s = "abc";
int *i = (int *) s;
printf("%x", *i);
}
That's not just system-specific, it's *bad*. Even if you're assuming
a particular set of characteristics for the platform, I can think
of at least four corrections that should be made (add '#include
<stdio.h>', use 'int main(void)', use unsigned int rather than int,
and add a 'return 0;') Not caring about portability is no excuse
for these errors.
--
Army1987 (Replace "NOSPAM" with "email")
No-one ever won a game by resigning. -- S. Tartakower
.
- Follow-Ups:
- Re: Puzzling program
- From: Keith Thompson
- Re: Puzzling program
- References:
- Puzzling program
- From: Rajeet Dalawal
- Re: Puzzling program
- From: Walter Roberson
- Re: Puzzling program
- From: Keith Thompson
- Re: Puzzling program
- From: Malcolm McLean
- Re: Puzzling program
- From: Mark McIntyre
- Re: Puzzling program
- From: Kenneth Brody
- Re: Puzzling program
- From: Keith Thompson
- Puzzling program
- Prev by Date: Re: Puzzling program
- Next by Date: Re: [xpost] a new C/C++ type that when overflow i see it
- Previous by thread: Re: Puzzling program
- Next by thread: Re: Puzzling program
- Index(es):
Relevant Pages
|