One way Which I could think of is to take diff of the addresses of two variables defined consecutively.

 

#define mysizeof(x) (int)&(x)[1] - (int)&(x)[0]

int main()

{

  int a = 4;

  int intsize = mysizeof(&a);

  char ab = 'A';

   int charsize = mysizeof(&ab);

  return 0;

}

 

Any way still I would like to know why you would like to stay away from using 'sizeof '?

 

...Regards

Pankaj Mishra


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Paul Herring
Sent: Friday, August 04, 2006 5:10 PM
To: [EMAIL PROTECTED]
Subject: {Disarmed} Re:
回复: Re: [c-prog] Related to sizeof() operator!

 

On 8/4/06, Linker M Lin <[EMAIL PROTECTED]> wrote:

None.


"None" what? No way of doing it? Of course there is. Whether you should be using the other methods is questionable however.

 

--- andrew clarke <[EMAIL PROTECTED]>写道:

> On Fri, Aug 04, 2006 at 06:50:58AM -0000, exedotsree wrote:
>
> > Is there any way to find the size of a variable without using the sizeof
> > (var/datatype) operator in C language?
>
> What for?




--
PJH

Into motorcycles? Need parts? Try www.gissit.com to contact lots of motorcycle breakers - free to use (UK based at the moment)

__._,_.___

To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.




SPONSORED LINKS
C programming language Programming languages Computer programming languages
Java programming language


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to