Hi all,
An object of a class A which has no member variables and no member
functions, still the size of the object is 1 byte, if there is a byte member
variable then also the size of the object is 1 byte. Could anyone tell me
the reason behind this.
Thanks
ishekara 8 3091
"ishekara" <is******@ishek ara.com> wrote in message Hi all,
An object of a class A which has no member variables and no member functions, still the size of the object is 1 byte, if there is a byte
member variable then also the size of the object is 1 byte. Could anyone tell me the reason behind this. http://www.research.att.com/~bs/bs_f...l#sizeof-empty
Sharad
>An object of a class A which has no member variables and no member functions, still the size of the object is 1 byte, if there is a byte
membervariable then also the size of the object is 1 byte. Could anyone tell
methe reason behind this.
There is no requirement in the C++ standard that an empty object should
have one byte of memory aoocupied. It is purely based on the
implementation.
ishekara wrote: Hi all,
An object of a class A which has no member variables and no member functions, still the size of the object is 1 byte, if there is a byte member variable then also the size of the object is 1 byte. Could anyone tell me the reason behind this.
Thanks ishekara
So that any and all instantiations ( objects ) of the empty version of
class A will have distinct addresses ( evidently at least one byte away
). Thus pointers, references et al of distinct objects will be different.
--
Cheers
--
Hewson::Mike
"This letter is longer than usual because I lack the time to make it
shorter" - Blaise Pascal
Shan wrote: An object of a class A which has no member variables and no member functions, still the size of the object is 1 byte, if there is a byte
member
variable then also the size of the object is 1 byte. Could anyone tell
me
the reason behind this.
There is no requirement in the C++ standard that an empty object should have one byte of memory aoocupied. It is purely based on the implementation.
Sorry :-)
but, not if it's conforming ( ISO/IEC 14882 p.149 ):
9 Classes [class]
..
..
..
3 Complete objects and member subobjects of class type shall have
nonzero size. ...
--
Cheers
--
Hewson::Mike
"This letter is longer than usual because I lack the time to make it
shorter" - Blaise Pascal
> 3 Complete objects and member subobjects of class type shall have nonzero size. ...
Sorry, i missed that....And thanks ;))
Shan wrote: 3 Complete objects and member subobjects of class type shall have nonzero size. ...
Sorry, i missed that....And thanks ;))
Actually I love the way English, as a common language, divides us. :-)
If I say "class X is of size 10 bytes", does that imply that "one byte
of memory occupied". Well yes, it does, but I just didn't mention the
other nine.
--
Cheers
--
Hewson::Mike
"This letter is longer than usual because I lack the time to make it
shorter" - Blaise Pascal
because a objeect's size can not be 0, it is a instance.
but sonetime,a class's size may be 0 when the class will haven't a
instance at anytime.
to read a words what was called "countting object in c++".by meyers.
you will get more things.
good luke
"Shan" <sh*******@redi ffmail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. . An object of a class A which has no member variables and no member functions, still the size of the object is 1 byte, if there is a byte membervariable then also the size of the object is 1 byte. Could anyone tell methe reason behind this.
There is no requirement in the C++ standard that an empty object should have one byte of memory aoocupied.
True, but it does require that it have a nonzero size.
It is purely based on the implementation.
Yes, the exact nonzero size is implementation-defined.
-Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jéjé |
last post by:
Hi everyone.
I'm currently implementing a Cache system.
Limiting its capacity with the number of object makes no sense, since
objects can have any size they want.
So I'd like to limit its capacity in term of number of bytes allready
cached. Therefore, I need to know what is the size in byte of any
object in the heap.
I thought about serializing the object to an array of byte, but this
|
by: pembed2003 |
last post by:
Hi all,
If I have the following:
class Foo{
void something(void){;}
};
and then later I say:
Foo f;
|
by: ThazKool |
last post by:
Is there anyway to write a class or struct that has no storage. It
only operates on a reference to an already existing type.
This is actually an extension to another thread. The thread went a
little off of what I was looking for. Hence this new thread.
Thanks,
ThazKool
|
by: spielmann |
last post by:
Hello
I want to change the scrollbar size of windows, How can I do that with
vb.net
I have find this in VB6 but how can we convert simply this code.
thx
|
by: Martin Robins |
last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return "DirectoryEntry" objects within the path that I specify (either using the DirectoryEnrtry.Children or using the DirectorySearcher class) and all started well and dandy!
Now the problem; some of the properties of the DirectoryEntry objects being...
| |
by: Dave |
last post by:
I am serialising an object to a memory mapped file (using the
CreateFileMapping and MapViewOfFile p/invoke calls). These need to know the
maximum size of the "file". I can put in a "good guess" ie it won't be more
than, say, 1K, but it would be tidier to use the actaul size. Is it actually
possible to find out how big an object (or even better, a class) would be
when it is serialised (I suppose one way would be to separately serialise it...
|
by: Harish |
last post by:
This was an interview question: The size of an empty class is 1 byte. Why?
Should it not be 4 bytes? Because an invisible pointer "this" is part of
every class?
|
by: Ajay |
last post by:
Hi all,
Please tell me why empty class has one Byte Size.
thanks in Advance..
Ajay
|
by: ggnguser |
last post by:
It's part of a test and I'm stumped. There is a function
void foo(char **x)
The function signature is given and cannot be changed, so no passing
of other values. The test case involves defining this variable:
char *y = { /* bunch of stuff */ }
and calling
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |