Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > sizeof( int ) != sizeof( void * )

Reply
Thread Tools

sizeof( int ) != sizeof( void * )

 
 
blufox
Guest
Posts: n/a
 
      05-22-2006
I read somewhere that standard Ansi C on 32 bit architecures assumes a
lot of things which lead to poor code.

For example
sizeof( int ) = sizeof( void * )
sizeof( long ) = sizeof( int )

Why is this poor code?
Am i missing something?

Thank you

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      05-22-2006
blufox said:

> I read somewhere that standard Ansi C on 32 bit architecures assumes a
> lot of things which lead to poor code.


"Ansi C on 32 bit architectures" doesn't really mean a great deal. If you
mean "programs supposedly written in ANSI C but relying in practice on
non-portable assumptions that happen to be true on the development
platform", then that is indeed meaningful.

> For example
> sizeof( int ) = sizeof( void * )
> sizeof( long ) = sizeof( int )
>
> Why is this poor code?


If sizeof(int) is not the same as sizeof(void *), then it's a bad idea to
assume it is. And of course the same applies to your second example.

Even if these assumptions happen to be true on the machine we are working on
today, they might not be true on the machine the boss suddenly decides to
buy tomorrow. And since he's spent all that money on supposedly portable C
programs, he's going to want to run those programs on that machine,
tomorrow. Writing the programs correctly in the first place is far easier
than explaining to your boss why you didn't.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      05-22-2006

"Richard Heathfield"
> blufox said:


>> I read somewhere that standard Ansi C on 32 bit architecures assumes a
>> lot of things which lead to poor code.


> "Ansi C on 32 bit architectures" doesn't really mean a great deal. If you
> mean "programs supposedly written in ANSI C but relying in practice on
> non-portable assumptions that happen to be true on the development
> platform", then that is indeed meaningful.

ANSI C on a 32 bit architecture probably means less to Richard than me, as I
struggle with producing something ISO with an OS that emulates 32 bit
processing on a 64 bit chip.

>> For example
>> sizeof( int ) = sizeof( void * )
>> sizeof( long ) = sizeof( int )
>>
>> Why is this poor code?

In the stated environment and with vendor-dependent implementation, that
would mean for me in both statements:
2 = 4
without the necessary semicolon to notify your compiler that you're making a
different error than you think.

> If sizeof(int) is not the same as sizeof(void *), then it's a bad idea to
> assume it is. And of course the same applies to your second example.
>
> Even if these assumptions happen to be true on the machine we are working
> on
> today, they might not be true on the machine the boss suddenly decides to
> buy tomorrow. And since he's spent all that money on supposedly portable C
> programs, he's going to want to run those programs on that machine,
> tomorrow. Writing the programs correctly in the first place is far easier
> than explaining to your boss why you didn't.


This last statement is true in a better world. joe


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between void proba(); and void proba(void); ??? PencoOdStip@gmail.com C++ 1 05-23-2007 07:12 PM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments