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

What is with the insanely huge temptation to make millions of typedefs of "int"???

God dang it all, i am so sick of programmers who feel compelled that
every single time they use an int variable, they give it some brand
new name! for example they would take an innocent function like
int multiply_by_2( int argument )

and change it to

multiply_by_2_return_t multiply_by_2( multiply_by_2_argument_t
argument )

What is the bloody point? Is it a deliberate attempt to render your
code unreadable?
Nov 13 '05 #1
3 1745
Trishia Rose wrote:
God dang it all, i am so sick of programmers who feel compelled that
every single time they use an int variable, they give it some brand
new name! for example they would take an innocent function like
int multiply_by_2( int argument )

and change it to

multiply_by_2_return_t multiply_by_2( multiply_by_2_argument_t
argument )

What is the bloody point? Is it a deliberate attempt to render your
code unreadable?


Actually, it's often an attempt to make things _more_ readable.

In the example you've quoted, of course, that attempt has failed.

<serious>
In some cases, there's a good reason to do this; sometimes you want to
decouple the concrete type of an argument (particularly of an integral
type) from the signatures of families of functions in order to account
for differences in platform. That way, the particular concrete type can
be dealt with through a typedef.
</serious>

HTH,
--ag

--
Artie Gold -- Austin, Texas

Nov 13 '05 #2
Trishia Rose wrote:
God dang it all, i am so sick of programmers who feel compelled that
every single time they use an int variable, they give it some brand
new name! for example they would take an innocent function like
int multiply_by_2( int argument )

and change it to

multiply_by_2_return_t multiply_by_2( multiply_by_2_argument_t
argument )

What is the bloody point? Is it a deliberate attempt to render your
code unreadable?


Depends on the environment. Sometimes the style is used to make code more
readable and sometimes it is used to establish something like a signature.
Often YOu want functions with the same name and different arguments. While
C++ supports this (and internally does something similar) You have to work
around in C.
A different application of this style is writing portable code. This way You
can typedef the neccesary machine dependency (usual at the start of the
file or in an extra header) and don't have to rewrite tons of code (while
You have to read tons of code to understand it -- nothing comes
costless:-(.

While it isn't so bad in principle, an overusing is of cause unreadable.
--
Best Regards
Sven
Nov 13 '05 #3
"Trishia Rose" <ad********@yahoo.com> wrote in message
news:b2**************************@posting.google.c om...
God dang it all, i am so sick of programmers who feel compelled that
every single time they use an int variable, they give it some brand
new name!


IMHO, to add additional information to the interface and the user's code.

An int is just an int -- the type says nothing about what it represents. A
frequency and a time delayare both (unsigned) integers, but they represent
very different and distinct concepts.

Typedeffing distinct types gives the user of an interface additional
information:

* it makes function prototypes more descriptive
* it discourages the user from assigning between variables of those types

It may also provide additional information for tools: for example, PC-Lint
can be configured to treat typedefs of integral types as strong types and
warn on inappropriate assignment.

It can, as you noted, be taken too far: I tend to typedef for quanties of
distinct physical units (FrequencyHzT; DelayMsT; and TimeoutMsT is distinct
as it has special "immediate" and "infinite" values) but not for quantities
of things (size-of-buffer, read-count, number-of-sectors).

--
James Kew
ja*******@btinternet.com
Nov 13 '05 #4

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

Similar topics

30
by: JKop | last post by:
When you want to store an integer in C++, you use an integral type, eg. int main() { unsigned char amount_legs_dog = 4; } In writing portable C++ code, there should be only two factors that...
5
by: Stuart | last post by:
Ok let me explain: I am writing a c# program that calls into an unmanaged C++ third-party DLL. I have to make a number of calls and for simplification the protype I am calling is: bool fn(int...
14
by: Matt | last post by:
I want to know if "int" is a primitive type, or an object? For example, the following two approaches yield the same result. > int t1 = int.Parse(TextBox2.Text); //method 1 > int t2 =...
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
4
by: C. J. Clegg | last post by:
A month or so ago I read a discussion about putting const ints in header files, and how one shouldn't put things in header files that allocate memory, etc. because they will generate multiple...
13
by: Anna | last post by:
I try to put 8 int bit for example 10100010 into one character of type char(1 octet) with no hope . Could anyone propose a simple way to do it? Thank you very much.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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
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
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.