473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

finding the size of a data structure in bytes?

I need to find the size of a class or struct in bytes, I did know how to do
it but I forgot and I can't find anything that tells me (I had a book with
it in but I lost it). You would think this kind of thing would be pretty
easy to find information on.
Jul 22 '05 #1
8 4675
Ragemare wrote:
I need to find the size of a class or struct in bytes, I did know how
to do it but I forgot and I can't find anything that tells me (I had
a book with it in but I lost it). You would think this kind of thing
would be pretty easy to find information on.


The sizeof operator:
sizeof yourclassorstructhere

It gives the size of your class or struct in units of the size of char.
(Which is usually a byte.)

- Pete
Jul 22 '05 #2
Ragemare wrote:
I need to find the size of a class or struct in bytes, I did know how
to do it but I forgot and I can't find anything that tells me (I had
a book with it in but I lost it). You would think this kind of thing
would be pretty easy to find information on.


The sizeof operator:
sizeof yourclassorstructhere

It gives the size of your class or struct in units of the size of char.
(Which is usually a byte.)

- Pete
Jul 22 '05 #3
Petec wrote:
Ragemare wrote:
I need to find the size of a class or struct in bytes, I did know how
to do it but I forgot and I can't find anything that tells me (I had
a book with it in but I lost it). You would think this kind of thing
would be pretty easy to find information on.

The sizeof operator:
sizeof yourclassorstructhere

It gives the size of your class or struct in units of the size of char.
(Which is usually a byte.)


Which is /by definition/ a byte. Always.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #4
Petec wrote:
Ragemare wrote:
I need to find the size of a class or struct in bytes, I did know how
to do it but I forgot and I can't find anything that tells me (I had
a book with it in but I lost it). You would think this kind of thing
would be pretty easy to find information on.

The sizeof operator:
sizeof yourclassorstructhere

It gives the size of your class or struct in units of the size of char.
(Which is usually a byte.)


Which is /by definition/ a byte. Always.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #5
Petec wrote:
Ragemare wrote:
I need to find the size of a class or struct in bytes, I did know how
to do it but I forgot and I can't find anything that tells me (I had
a book with it in but I lost it). You would think this kind of thing
would be pretty easy to find information on.

The sizeof operator:
sizeof yourclassorstructhere


sizeof(some_type)

or

sizeof an_instance_of_some_type
[Using parenthesis in this second case wouldn't be incorrect, but would
obfuscate its purpose.]

HTH,
--ag

--
Artie Gold -- Austin, Texas
Jul 22 '05 #6
Petec wrote:
Ragemare wrote:
I need to find the size of a class or struct in bytes, I did know how
to do it but I forgot and I can't find anything that tells me (I had
a book with it in but I lost it). You would think this kind of thing
would be pretty easy to find information on.

The sizeof operator:
sizeof yourclassorstructhere


sizeof(some_type)

or

sizeof an_instance_of_some_type
[Using parenthesis in this second case wouldn't be incorrect, but would
obfuscate its purpose.]

HTH,
--ag

--
Artie Gold -- Austin, Texas
Jul 22 '05 #7
Kevin Goodsell <us*********************@neverbox.com> wrote in message news:<wY***************@newsread1.news.pas.earthli nk.net>...
Petec wrote:
Ragemare wrote:
I need to find the size of a class or struct in bytes, I did know how
to do it but I forgot and I can't find anything that tells me (I had
a book with it in but I lost it). You would think this kind of thing
would be pretty easy to find information on.

The sizeof operator:
sizeof yourclassorstructhere

It gives the size of your class or struct in units of the size of char.
(Which is usually a byte.)


Which is /by definition/ a byte. Always.

-Kevin


Just to add up clarity, the bitwise size of this c++ byte may be more
than 8 bits. This is different than more widely perceived term "byte"
in context of marketing materials for specific platforms, where it is
understood to be 8 bit in size. In c++, byte is defined as unit of
addressability.
Jul 22 '05 #8
Kevin Goodsell <us*********************@neverbox.com> wrote in message news:<wY***************@newsread1.news.pas.earthli nk.net>...
Petec wrote:
Ragemare wrote:
I need to find the size of a class or struct in bytes, I did know how
to do it but I forgot and I can't find anything that tells me (I had
a book with it in but I lost it). You would think this kind of thing
would be pretty easy to find information on.

The sizeof operator:
sizeof yourclassorstructhere

It gives the size of your class or struct in units of the size of char.
(Which is usually a byte.)


Which is /by definition/ a byte. Always.

-Kevin


Just to add up clarity, the bitwise size of this c++ byte may be more
than 8 bits. This is different than more widely perceived term "byte"
in context of marketing materials for specific platforms, where it is
understood to be 8 bit in size. In c++, byte is defined as unit of
addressability.
Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ragemare | last post by:
I need to find the size of a class or struct in bytes, I did know how to do it but I forgot and I can't find anything that tells me (I had a book with it in but I lost it). You would think this...
8
by: Bryan Feeney | last post by:
This structure is, according to sizeof, 3 bytes long, which makes sense struct test { char text; }; This structure is, according to sizeof, 4 bytes long, which also makes sense struct...
22
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a...
18
by: Anand Buddhdev | last post by:
Hi everyone, I'm a C newbie, so please be gentle. I have a program that defines the following things: typedef union { unsigned int I; unsigned char b; } dword;
7
by: ANaiveProgrammer | last post by:
Hi all I have made the following two structs and size is not according to what is supposed to be, so please ponder over following and identify if im wrong... please also mention what would be...
19
by: junky_fellow | last post by:
Can the size of pointer variables of different type may be different on a particular architecture. For eg. Can the sizeof (char *) be different from sizeof(int *) or sizeof (void *) ? What...
20
by: Joel Hedlund | last post by:
Hi all! I use python for writing terminal applications and I have been bothered by how hard it seems to be to determine the terminal size. What is the best way of doing this? At the end I've...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
56
by: Bruce. | last post by:
I would like to allocate a structure size of 1024 bytes but I want the compiler to do the calculation for me. typedef struct { int var1; int var2; int var3; char ...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.