Re: Puzzling program
Kenneth Brody <kenbrody@spamc op.netwrites:
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.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Kenneth Brody <kenbrody@spamc op.netwrites:
Mark McIntyre wrote:
>
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?)
>On Thu, 9 Aug 2007 00:26:19 +0100, in comp.lang.c , "Malcolm McLean"
><regniztar@bti nternet.comwrot e:
>>
>>
>Euh, interviews are two-way. Do you really want to work for a company
>which employs people who don't care about code errors?
><regniztar@bti nternet.comwrot e:
>>
>You could point out all the errors and nonportable assumptions in the code.
>But you are not interviewing the interviewer, probably.
>But you are not interviewing the interviewer, probably.
>Euh, interviews are two-way. Do you really want to work for a company
>which employs people who don't care about code errors?
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?)
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.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Comment