473,396 Members | 2,068 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,396 software developers and data experts.

c doughts

what is the padding in c?
Jun 13 '07 #1
6 1613
Silent1Mezzo
208 100+
what is the padding in c?
This should go in the Forums not in the articles
Jun 13 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
I am moving this to the C/C++ Forum.

Padding is a term applied to the alignment of the variables in your code. Most compilers align on an int boundary. If you have a struct:

Expand|Select|Wrap|Line Numbers
  1. struct test
  2. {
  3.      int a;
  4.      char b;
  5.      int c;
  6. };
  7.  
the compiler will align the ints on an int boundary. To do that, three pad bytes will be inserted after member b. Normally, you need no worry about padding as it is handled internally by the compiler.
Jun 13 '07 #3
Silent1Mezzo
208 100+
Expand|Select|Wrap|Line Numbers
  1. struct test
  2. {
  3.      int a;
  4.      char b;
  5.      int c;
  6. };
  7.  
It's also the reason why:
Expand|Select|Wrap|Line Numbers
  1. sizeof(test) != sizeof(a) + sizeof(b) + sizeof(c) 
Jun 13 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
It's also the reason why:

Code: ( c )
sizeof(test) != sizeof(a) + sizeof(b) + sizeof(c)
Yep. I remember when I first did that. To quote Bugs Bunny, "Nyah, it don't add up, doc".
Jun 13 '07 #5
how much space does an object in c++ eats up when it is declared/initialised?[/b]
Jun 13 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
[quote=abhielementx786]

how much space does an object in c++ eats up when it is declared/initialised?

[/qoute]
The same as a struct since classes are implemented as a struct. The one difference is that if the struct/class contains a virtual function, the object will contain the address of the virtual function table. In this case the C++ object is larger by the sizeof a pointer.
Jun 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: M.Senthil Kumar | last post by:
hai all, I need a help from you. I 'm working in a project using "curses.h" in Linux using 'C'. I have some doughts regarding menus and line. 1. I used to draw box in window using...
1
by: anilkoli | last post by:
When object are serialized they are stored physically in a file(e.g. XML). But if I want to deal with remote computers I have to provide details about file where object is serialized or send that...
0
by: anilkoli | last post by:
I want clear cut idea about callbacks and also of delegates I have doughts about callbacks, I feel callbacks are used for 1. recursion 2. dynamically calling a perticular method out of many...
0
by: naish | last post by:
Hi, My code drawing a graph in excel sheet. There one colum for lower pressure and another one for upper pressure. Any howi can draw a series for one pressure but i am not able to draw two series...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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.