473,624 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Endianness of structure/union

SSM
Hi,

Does C standard comment about "Endianness " to be used
to store a structure/union variables?

Thanks & Regards,
Mehta
Nov 15 '05 #1
2 4024
"SSM" <sh************ *******@de.bosc h.com> wrote:
Does C standard comment about "Endianness " to be used
to store a structure/union variables?


Not if you mean the endianness of the various members themselves. What
it does require is that:
- for a union, all members start at the same address, which is also the
base address of the union;
- for a struct, all non-bitfield members start at different addresses,
with the first declared member having the lowest address, and so on in
order of declaration;
- bit field members have no address as such;
- there may be padding between two struct members and after the last,
but not before the first.

This is similar, but not equal, to endianness.

Richard
Nov 15 '05 #2
"SSM" <sh************ *******@de.bosc h.com> wrote in message
news:dh******** **@ns2.fe.inter net.bosch.com.. .
Does C standard comment about "Endianness " to be used
to store a structure/union variables?


AFAIK, no. It can be anything, depending on the CPU for which you compile
your source code.

The only place in an application where endianness would matter is I/O (file
system, network or any other device consuming and producing data in big
chunks). Only there you should care about the endianness if you exchange
data with anything else but your own application.

There's a way to make the application more portable across systems with
different endianness. Send/receive integer numbers octet per octet (note
that by octet I mean an 8-bit integer, which is not necessarily a byte/char
as byte/char has different bits on different systems) in a fully defined
order, either least significant first or most significant first -- pick one
and stick to it. Slice the numbers into octets by shifting and masking --
this will make it independent from the CPU's endianness. It's OK to send the
numbers as text too :) but that's obviously too much of overhead in many
applications. The raw data, which you don't know and don't process, is to be
sent as-is, preferrably as octets too, best if octet=byte(char ), if this
equality doesn't hold (byte/char is bigger than octet), then you must make a
decision as to how to get it out, as octets or as bytes/chars and if as
octets how you slice the date into them (again, least significant first or
most significant first).

Alex
Nov 15 '05 #3

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

Similar topics

3
8095
by: Memduh Durmaz | last post by:
Hi, I'm using DB2 UDB 7.2. Also I'm doing some tests on SQL Server 2000 for some statements to use efectively. I didn't find any solution on Sql Server about WITH ... SELECT structure of DB2. Is there any basic structure on Sql Server like WITH ... SELECT structure?
2
2518
by: Jeff Massung | last post by:
I am having a syntax issue that I hope someone else here knows how to rectify... I am loading an INI file and have a simple function to load values from it. The function is overloaded with the different return types int, double or string. A structure is defined: typedef struct INI_KEY { char strCategory; char strKey;
10
11377
by: tapeesh | last post by:
I created a C file say struct.c with the following structure declarations in the same file struct A { union key { int i; float f; }k1;
8
3317
by: Charles Law | last post by:
Can anyone suggest how I would marshal a variable length structure back from an API call. Specifically, I am looking at the WaitForDebugEvent function, which returns a DEBUG_EVENT structure. However, the DEBUG_EVENT structure is defined as a union, and the size and contents vary depending on the event code contained in the header. typedef struct _DEBUG_EVENT { DWORD dwDebugEventCode; DWORD dwProcessId;
6
5298
by: Tomás | last post by:
Let's say you want to write fully portable code that will be writing files or sending data, and the data is text encoded using Unicode 16-Bit. Endianness comes into play. I'm writing code at the moment which determines the Endianness of the architecture, and then converts values to Bigendian if they need to be converted. At the moment my code is based around: typedef unsigned short uint16;
5
2633
by: xmllmx | last post by:
Please forgive me for cross-posting. I've post this to microsoft.publoc.vc.mfc. But I can't get any response. Maybe only MFC- related topics are cared there. To begin with code: union XXX { double a; char b;
19
6922
by: perry.yuan | last post by:
How could I determine the endianness of my compile environment at compile time, instead of run time? I need a macro ("some_expression"), i.e. #if some_expression #define TARGET_IS_LITTLE_ENDIAN #else #define TARGET_IS_BIG_ENDIAN No way or some way? TIA.
5
6381
by: hnshashi | last post by:
I have writtem kernel(2.4) module to commu. with user space appl. using netlink socket. I am getting compilation error. kernel module:-> #include <linux/skbuff.h> #include<linux/module.h> #include <linux/socket.h> #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h>
8
3242
by: Andrew Smallshaw | last post by:
I'm working on a data structure that began life as a skip list derivative, but has evolved to the point that it now only has a passing resemblance to them. Each node of this structure has a few constant size variables (ints and the like), an array holding the actual data (chars in this case) and a random number of pointers to other nodes in the structure. At the moment my code uses a fixed size array for the contents (which may or may...
0
8236
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, 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...
0
8173
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,...
0
8679
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, 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...
0
8621
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7159
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2606
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
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.