$ cat sizeof.c
#include <stdio.h>
#include <sys/types.h>
#define SIZEOF(var) ((size_t)(&(var)+1)-(size_t)(&(var)))
struct test
{
int a;
int b;
} A;
int
main ( void )
{
int num;
char ch;
printf ( "sizeof int = %d\n", SIZEOF(num));
printf ( "sizeof char = %d\n", SIZEOF(ch));
printf ( "sizeof struct = %d\n", SIZEOF(A));
printf ( "sizeof int = %d\n", SIZEOF(int));
return 0;
}
$$ cc sizeof.c
sizeof.c: In function âmainâ:
sizeof.c:20: error: invalid lvalue in unary â&â
sizeof.c:20: error: expected expression before â)â token
$
--- On Mon, 11/3/08, Amaresh Chandra Das <[EMAIL PROTECTED]> wrote:
From: Amaresh Chandra Das <[EMAIL PROTECTED]>
Subject: Re: [c-forum] Re: [c-prog] how to find size without using sizeof??
To: [email protected], [EMAIL PROTECTED]
Date: Monday, November 3, 2008, 11:03 AM
No Ganesh,
"#define my_sizeof(var) ((size_t)(&(var) + 1) - (size_t)(&(var)))" is working
fine .
Thanks and regards
Amaresh Ch Das
+91-9886720068
--- On Mon, 3/11/08, Ganesh Kundapur
<[EMAIL PROTECTED] com> wrote:
From: Ganesh Kundapur <[EMAIL PROTECTED] com>
Subject: Re: [c-forum] Re: [c-prog] how to find size without using sizeof??
To: [EMAIL PROTECTED] com, [EMAIL PROTECTED] .co.in
Date: Monday, 3 November, 2008, 10:50 AM
This wont work for keywords as my_sizeof(int) or my_sizeof(char)
gives an error.
To find the sizeof keywords we need to define one more macro as fallows
#define sizeof_type( type) ((size_t)((type *)0+1)
/Ganesh
--- On Mon, 11/3/08, Rajath N R <[EMAIL PROTECTED] com> wrote:
From: Rajath N R <[EMAIL PROTECTED] com>
Subject: [c-forum] Re: [c-prog] how to find size without using sizeof??
To: [EMAIL PROTECTED] com, "c-form" <[EMAIL PROTECTED] .co.in>
Date: Monday, November 3, 2008, 10:28 AM
Hi,
check this........ ......... ...
#include <stdio.h>
#include <sys/types.h>
#define my_sizeof(var) ((size_t)(&(var) + 1) - (size_t)(&(var)))
struct test {
int a;
int b;
};
struct test a1;
main()
{
int num;
char ch;
printf("%d\n" , my_sizeof(num) );
printf("%d\n" , my_sizeof(ch)
);
printf("%d\n" , my_sizeof(a1) );
}
Thanks & Regards,
Rajath N R
--- On Sun, 11/2/08, una_020 <[EMAIL PROTECTED] co.in> wrote:
From: una_020 <[EMAIL PROTECTED] co.in>
Subject: [c-prog] how to find size without using sizeof??
To: [EMAIL PROTECTED] com
Date: Sunday, November 2, 2008, 7:28 AM
1.how to find size of structure without using sizeof operator?
2.variable name i.e. identifier is given how to find it's size without
using sizeof?
Connect with friends all over the world. Get Yahoo! India Messenger.
[Non-text portions of this message have been removed]