473,378 Members | 1,415 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,378 software developers and data experts.

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 4000
"SSM" <sh*******************@de.bosch.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.bosch.com> wrote in message
news:dh**********@ns2.fe.internet.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
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. ...
2
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...
10
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
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. ...
6
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...
5
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 {...
19
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...
5
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> ...
8
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...
1
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.