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

struct alignment

Can anyone explain what is meant by alignment in data structure in C
language. What happens internally by changing the align value. Thanks
in advance. Russell

Nov 14 '05 #1
2 2024
>Can anyone explain what is meant by alignment in data structure in C
language. What happens internally by changing the align value. Thanks
in advance. Russell


You don't get to change the alignment. Only a compiler implementor
does.

Alignment is a requirement that certain data types must be stored
at an address that is a multiple of some constant for that type,
due to hardware requirements (if you violate them, you get some
kind of exception) or optimization (aligning doubles to a multiple
of, say, 4 speeds up loading them from memory). For example, a
data type of size 4 bytes might be aligned to a multiple of 4 bytes.

Different alignment requirements sometimes mean different sizes for
the same structure on different machines, and differing amounts of
padding between elements.

Gordon L. Burditt
Nov 14 '05 #2

<ra*****@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Can anyone explain what is meant by alignment in data structure in C
language. What happens internally by changing the align value. Thanks
in advance. Russell

A compiler is likely to leave unused space (padding) between structs or
between fields of differing types, to allow for access by the load and store
instructions associated with the type. There is often a pragma to override
this (packed storage), or a compiler option to set a lower ceiling on the
amount of padding. A common consequence would be inability to use wide
loads and stores, such as the 128-bit parallel instructions provided by
several common architectures. Compiling parts of a program with inconsistent
alignment options could lead to run-time failure.
Nov 14 '05 #3

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

Similar topics

2
by: Matt Feinstein | last post by:
Using the 'struct' module (Win32, python version 2.4.1)-- The library documentation says that 'no alignment is required for any type'. However, struct.calcsize('fd') gives 16 while...
3
by: Chandu | last post by:
In using the following struct format I get the size as 593. The same C struct is 590 if packed on byte boundary and 596 when using pragma pack(4). I am using pack(4) and added 3 spares at the end...
5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
67
by: S.Tobias | last post by:
I would like to check if I understand the following excerpt correctly: 6.2.5#26 (Types): All pointers to structure types shall have the same representation and alignment requirements as each...
36
by: Eric Laberge | last post by:
Hi! I'm working on automatically generated code, and need to assign arrays. memcpy is an obvious solution, but it becomes complicated to use in the context I'm working on, ie.: I could use it...
8
by: Chameleon | last post by:
I have a TGA image header struct. TGA has 18 bytes header, so the C struct too. why this return 20? sizeof(TGAHeader) I saw this in many structs. I believe compiler round up the size to 4...
11
by: simonp | last post by:
I'm taking an intro course on C++, and our teacher is not being clear on how stuct memory padding is determined. If the memory used by all components defined inside a struct falls between a...
6
by: Jack | last post by:
Hi, All, is it possible to send a struct using the the send function. Here is what I mean typedef struct{ int ID; char name; }sampleStruct; int main(){
8
by: anon.asdf | last post by:
Hi! OK, lets try "array-copy": { char arrayA; arrayA = (char){1, 2, 3}; } it does *not* work since we're trying to make a fixed array-pointer arrayA, point to another location/address...
6
by: Francois Grieu | last post by:
Hello, I'm asking myself all kind of questions on allocating an array of struct with proper alignment. Is the following code oorrect ? I'm most interested by the statement t =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.