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

definition of u_int32

i am new to c language i come across some definitions like unsigned int
long int32 i want to know why such assignments are mentioned and what
does it mean?

May 10 '06 #1
4 7539

raghu wrote:
i am new to c language i come across some definitions like unsigned int
long int32 i want to know why such assignments are mentioned and what
does it mean?


I guess you came across:

typedef unsigned long int u_int32;

It means that now you can declare variables like this:

u_int32 i;

and it will mean exactly the same as:

unsigned long int i;

As to why someone would want to do this, there are several answers: to
save typing
; to tell the reader that the variable is 32 bits and unsigned.

Both of these are IMO wrong, and here's why:

The `unsigned long` type may not be 32 bits on all
implementations/architectures, so you'd actually introduce subtle bugs
if you relied on the new type name alone. You've just made your program
not portable.

Saving on typing is no saving really. You only type once, but the code
is read many times, and by various people. For the readers, it may be
more useful, and possibly safer as I described above, to know exactly
what you're doing.

BTW, the C standard provides for a way to specify exact width. Have a
look at <stdint.h> header for your implementation. The type names are
of the form `[u]intN_t` where `u` siginfies unsigendness, and N is the
width in number of bits.

May 10 '06 #2
Vladimir Oka wrote:
raghu wrote:
i am new to c language i come across some definitions like unsigned int
long int32 i want to know why such assignments are mentioned and what
does it mean?
I guess you came across:

typedef unsigned long int u_int32;

It means that now you can declare variables like this:

u_int32 i;

and it will mean exactly the same as:

unsigned long int i;

As to why someone would want to do this, there are several answers: to
save typing
; to tell the reader that the variable is 32 bits and unsigned.

Both of these are IMO wrong, and here's why:

The `unsigned long` type may not be 32 bits on all
implementations/architectures, so you'd actually introduce subtle bugs
if you relied on the new type name alone. You've just made your program
not portable.


This is not wrong if guarded by appropriate macros to either select the
correct type (if it exists) or ensure the typedef is correct.
Saving on typing is no saving really. You only type once, but the code
is read many times, and by various people. For the readers, it may be
more useful, and possibly safer as I described above, to know exactly
what you're doing.
Saving typing is not a valid reason, but if defined properly telling the
reader it is 32 bits is, assuming that really is what the programmer
intends.
BTW, the C standard provides for a way to specify exact width. Have a
look at <stdint.h> header for your implementation. The type names are
of the form `[u]intN_t` where `u` siginfies unsigendness, and N is the
width in number of bits.


That was only added in C99, for some strange reason I can't find that
header anywhere on my MS VC++ install despite it being the latest version!

Unfortunately most C implementations are not compliant to C99 and some
are not even attempting to move towards C99.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 10 '06 #3
Flash Gordon wrote:
That was only added in C99, for some strange reason I can't find that
header anywhere on my MS VC++ install
despite it being the latest version!
Maybe it has something to do with
headers not being called "header files".
Unfortunately most C implementations are not compliant to C99 and some
are not even attempting to move towards C99.


Or maybe not.

--
pete
May 10 '06 #4
pete wrote:
Flash Gordon wrote:
That was only added in C99, for some strange reason I can't find that
header anywhere on my MS VC++ install
despite it being the latest version!


Maybe it has something to do with
headers not being called "header files".
Unfortunately most C implementations are not compliant to C99 and some
are not even attempting to move towards C99.


Or maybe not.


Definitely not. Try to include it stdint.h a program and the program
will fail to compile. Unless you provide your own version, of course.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
May 10 '06 #5

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

Similar topics

9
by: Dave H | last post by:
Hello, I have a query regarding definition lists. Is it good practice semantically to use the dt and dd elements to mark up questions and answers in a frequently asked questions list, or FAQ? ...
7
by: Neil Zanella | last post by:
Hello, I have posted the following message before but got no replies... I am trying to format an HTML definition list with CSS so that it appears as follows, but am having the following problem:...
14
by: Mike Hewson | last post by:
Have been researching as to why: <example 1> class ABC { static const float some_float = 3.3f; }; <end example 1>
19
by: J. J. Farrell | last post by:
After many years of dealing with definition and linkage issues in ways that I know to be safe, I've decided it's time to try to understand this area properly. Consider a header file with the file...
4
by: Ced | last post by:
Hi, i'm not an expert in C but i try to compile BTNG software under linux kernel 2.4.2-2. I get these errors at the very first stage. Does someone could have a rapid look on this and tell me...
10
by: Kobu | last post by:
My question is about the use and meaning of the terms "declaration" and "definition" as it pertains to the C language. I've read sources that mix the two up when talking about such things as...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
15
by: vaib | last post by:
hi to all.i'd like to know the actual difference between variable declaration and definition.it would be very helpful if anyone out there wud help me out with this thing.i'm writing here after here...
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: 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...
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
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...
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
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
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...

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.