[comp.sys.mac.programmer] MPW C int size

J.Pearce@cs.ucl.ac.uk (11/14/90)

Could someone please tell how MPW C represents a "plain" int -
is it 2 or 4 bytes.

Many thanks,

John Pearce

jpearce@uk.ac.ucl.cs

Computer Science Department
University College London

leyser@nitrex.UUCP (Jeff Leyser) (11/16/90)

In post <1278@ucl-cs.uucp>, J.Pearce@cs.ucl.ac.uk says:
!
!Could someone please tell how MPW C represents a "plain" int -
!is it 2 or 4 bytes.

I don't have MPW.  But compile and run this:

main() {
	printf("An int is %d bytes\n",sizeof(int));
}
-- 
Jeff Leyser			Hey, would *you* be a spokesman for
leyser@nitrex.UUCP.		a Big Oil Company(tm)?

hanche@imf.unit.no (Harald Hanche-Olsen) (11/18/90)

In article <505@nitrex.UUCP> leyser@nitrex.UUCP (Jeff Leyser) writes:

   main() {
	   printf("An int is %d bytes\n",sizeof(int));
   }

Actually, that code isn't portable.  What if sizeof() returns a long?
It often does.  Of course, it is often the case that int == long, so
on most compilers you won't notice the difference.  I really don't
know how to make a piece of code like the above portable, unless you
say things like

	   printf("An int is %ld bytes\n",(long)sizeof(int));

Yeah, that should do it.  Or should that be unsigned long?  Ahhh, the
joys of portable programming...

- Harald Hanche-Olsen <hanche@imf.unit.no>
  Division of Mathematical Sciences
  The Norwegian Institute of Technology
  N-7034 Trondheim, NORWAY

Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) (11/18/90)

MPW ints are 4 byte values versus Think C and its 2 byte values. MPW 
shorts are 2 bytes and if you use long you'll get 4 byte values (same as 
the int).


--  

   	Ken Knight, Ken.Knight@f421.n109.z1.fidonet.org
   	via The Black Cat's Shack's FidoNet<->Usenet Gateway
	    blkcat.fidonet.org   and   Fidonet 1:109/401

d88-jwa@dront.nada.kth.se (Jon W{tte) (11/18/90)

In article <HANCHE.90Nov17172757@hufsa.imf.unit.no> hanche@imf.unit.no (Harald Hanche-Olsen) writes:
>In article <505@nitrex.UUCP> leyser@nitrex.UUCP (Jeff Leyser) writes:

>   main() {
>	   printf("An int is %d bytes\n",sizeof(int));
>   }

>Actually, that code isn't portable.  What if sizeof() returns a long?
>It often does.  Of course, it is often the case that int == long, so

The

printf ( "%ld" , ( long ) sizeof ( int ) ) ;

should work. If it's unsigned or signed doesn't matter, since
the result very seldom is > 8 ( or negative :-)

							h+
h+@nada.kth.se
"Moof!(tm)"

Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) (11/20/90)

leyser@nitrex.UUCP (Jeff Leyser) Writes:

> In post <1278@ucl-cs.uucp>, J.Pearce@cs.ucl.ac.uk says:
> !
> !Could someone please tell how MPW C represents a "plain" int -
> !is it 2 or 4 bytes.
> 
> I don't have MPW.  But compile and run this:
> 
> main() {
>         printf("An int is %d bytes\n",sizeof(int));
> }

Just to end the suspense, it's 4 bytes.

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!56.12!Chris.Gehlker
Internet: Chris.Gehlker@p12.f56.n114.z1.fidonet.org