LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-28-2004, 02:29 AM   #1
hiren
LQ Newbie
 
Registered: Sep 2004
Posts: 5

Rep: Reputation: 0
Sizeof Operator Implementation


Dear Memebers,

I want to know how the Sizeof Operator is implemented and also What does matter when deciding the size of Interger? Why it is 2 bytes in Windows and 4 bytes in Linux.

Could anyone help me out? I have tried searching on Net but couldn't able to find out.

Thank you,
Hiren Gajjar.
 
Old 09-28-2004, 04:02 AM   #2
ananthbv
Member
 
Registered: Nov 2003
Posts: 49

Rep: Reputation: 15
hi, i think sizeof() is implemented somewhat like this
Code:
#define sizeof(x)  ((void *)(&x + 1) - (void *)(&x))
and the size of an int depends on the hardware, particularly the Arithmetic and Logic Unit(ALU).
 
Old 09-28-2004, 04:14 AM   #3
hiren
LQ Newbie
 
Registered: Sep 2004
Posts: 5

Original Poster
Rep: Reputation: 0
I don't think so. Because sizeof operator will also accept Data types.. like sizeof(int), sizeof(char)...

Thanks.
Hiren Gajjar.
 
Old 09-28-2004, 04:30 AM   #4
ananthbv
Member
 
Registered: Nov 2003
Posts: 49

Rep: Reputation: 15
yeah, that occured to me later , maybe datatypes are checked for before variables.
 
Old 09-28-2004, 10:32 AM   #5
Sadrul
LQ Newbie
 
Registered: Mar 2004
Distribution: Slackware 10.0 (K: 2.4.26)
Posts: 13

Rep: Reputation: 0
`int' is 2 bytes in Turbo C/C++, because TC is a 16-bit compiler. if you compile in Visual C (which is a 32-bit compiler), you will see that `int' is 4 bytes. all compilers (that i know of) in linux are 32 bit compilers. so `int' always shows 4 bytes in gcc.

i don't know much about the implementation of the `sizeof' operator.

-- Adil
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sizeof operator implementation vinods Programming 1 10-26-2004 09:57 AM
when does sizeof ( ) operator return zero !! joeyBig Programming 3 10-01-2004 06:43 AM
How Sizeof Operator Implemented? hiren Linux - General 4 09-29-2004 05:12 AM
Shell '>' operator implementation Lord CyKill Programming 1 10-14-2003 04:07 PM
sizeof() and C/C++ boku Programming 2 09-01-2002 07:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration