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

Type aliases

Is it still common practice to use type aliases (INT, PCHAR etc).

It looks ugly and breaks the syntax highlighting, are there any
advantages these days (MSVC++6.0 and later)? I could understand it,
maybe, back in the days when some compilers had 16 bit ints.

Also, if your products is heavily dependent on a 3rd party library
which just uses the raw types, does the aliasing help in any way at
all?
Mar 21 '08 #1
6 2111
do*********@googlemail.com wrote:
Is it still common practice to use type aliases (INT, PCHAR etc).
It depends what those aliases are for. INT instead of int makes
no sense, neither does PCHAR instead of char*. However, there are
probably some places where WORD is bettern than unsigned short
(like in a functional style cast) or DWORD instead of unsigned long
(for similar reasons). [you can see I've been working in Windows]
It looks ugly and breaks the syntax highlighting, are there any
advantages these days (MSVC++6.0 and later)? I could understand it,
maybe, back in the days when some compilers had 16 bit ints.
Uh... How do 16-bit ints play into the type aliasing?
Also, if your products is heavily dependent on a 3rd party library
which just uses the raw types, does the aliasing help in any way at
all?
No, but ask the reverse question.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 21 '08 #2
Victor Bazarov wrote:
do*********@googlemail.com wrote:
>Is it still common practice to use type aliases (INT, PCHAR etc).

It depends what those aliases are for. INT instead of int makes
no sense, neither does PCHAR instead of char*.
IMHO, the funniest one is VOID instead of void.
However, there are probably some places where WORD is bettern than
unsigned short (like in a functional style cast) or DWORD instead of
unsigned long (for similar reasons). [you can see I've been working in
Windows]
But why the ugly ALL-UPPERCASE typedef names? Also, "word" can have
diffferent meanings. On ARM CPUs for example, a word is 32 bits wide, while
on x86, it is only 16 bits.
Nowadays, I prefer to use the typedefs from the C99 stdint.h header, which
hopefully make it into the next C++ standard too. Most C++ compilers have
it anyway.

Mar 21 '08 #3
do*********@googlemail.com wrote:
On Mar 21, 1:53 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>dom.k.bl...@googlemail.com wrote:
>>Also, if your products is heavily dependent on a 3rd party library
which just uses the raw types, does the aliasing help in any way at
all?

No, but ask the reverse question.

If you mean does the aliasing do any harm, well I'd say it does. It is
ugly and it stops syntax highlighting working, to name two. If it has
absolutely no upside, then any downside is enough to say you shouldn't
use it.
No, I meant if your products are heavily dependent on a 3rd party
library that does use aliases (at least in their declarations) and
provide those aliases (of course), would it be beneficial to keep
using those aliases in your own code even if you don't intend to
call their functions? If not, why?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 21 '08 #4
On Mar 21, 4:02 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
dom.k.bl...@googlemail.com wrote:
On Mar 21, 1:53 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
dom.k.bl...@googlemail.com wrote:
Also, if your products is heavily dependent on a 3rd party library
which just uses the raw types, does the aliasing help in any way at
all?
No, but ask the reverse question.
If you mean does the aliasing do any harm, well I'd say it does. It is
ugly and it stops syntax highlighting working, to name two. If it has
absolutely no upside, then any downside is enough to say you shouldn't
use it.

No, I meant if your products are heavily dependent on a 3rd party
library that does use aliases (at least in their declarations) and
provide those aliases (of course), would it be beneficial to keep
using those aliases in your own code even if you don't intend to
call their functions? If not, why?
Well I use a number of third party libraries, a couple each have their
own aliases, and I would absolutely not base my own code on them.
Which one would I choose? And what would happen to my code if the
third party changed the definitions?

They have at least prefixed the aliases with a library specific prefix
(another reason I wouldn't base my own code on them), but they get
cast right at the lowest possible level. I tend to try to isolate the
interface in a single module as far as is practical.

The worst thing is when 2 libraries both use their own versions of the
standard aliases (INT, CHAR etc).
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 21 '08 #5
Rolf Magnus <ra******@t-online.dewrote in
news:fs*************@news.t-online.com:
>
But why the ugly ALL-UPPERCASE typedef names? Also, "word" can have
diffferent meanings. On ARM CPUs for example, a word is 32 bits wide,
while on x86, it is only 16 bits.
Nowadays, I prefer to use the typedefs from the C99 stdint.h header,
which hopefully make it into the next C++ standard too. Most C++
compilers have it anyway.

Consistency. Originally MS started doing that so they could decorate
pointer types with appropriate __far, __near, __declspec etc (depending on
memory model and other switches). The rest sort of carries from that. I'm
not claiming they have a place in modern code, but sometimes history has
its way with you regardless.

joe
Mar 21 '08 #6
On 21 mar, 13:59, dom.k.bl...@googlemail.com wrote:
Is it still common practice to use type aliases (INT, PCHAR etc).
It never was, as far as I can tell (and my C/C++ experience goes
back to the early 1980's).
It looks ugly and breaks the syntax highlighting, are there
any advantages these days (MSVC++6.0 and later)? I could
understand it, maybe, back in the days when some compilers had
16 bit ints.
Most of the C I wrote was for 16 bit machines, and I've never
seen such conventions. They look like pure obfuscation to me.
Also, if your products is heavily dependent on a 3rd party
library which just uses the raw types, does the aliasing help
in any way at all?
Aliasing as in your examples actively hurts.

Aliasing can be useful if the names give additional semantic
information:
typedef int WidgitCount ;
, for example, especially when linked to types which can change
from one implementation to the next, e.g. off_t under Posix.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Mar 22 '08 #7

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

Similar topics

0
by: Andrew | last post by:
With command-line interface ( 3.23.37, UNIX Socket ) all is well with column aliasing. However, column aliases disappear in Excel, over ODBC, when there are multiple (joined) tables in the query. ...
5
by: Kevin | last post by:
I'm making my first attempt to put embedded SQL in a visual C++ application and I'm having trouble getting aliases to work. If I try the following SQL query on MS SQL 7.0 it works fine. SELECT...
0
by: Krzysiek | last post by:
Hi all, I have an issue with QSYS\QADBXREF file - it keeps aliases on tables. I take care of an application that works on many places (servers) and on one of them it's not possible to create...
5
by: Joe Bloggs | last post by:
Hi, I would like to programatically resolve aliases to the actual type, eg. int to System.Int32. Essentially, I would like to do this: Type t = Type.GetType(ResolveAlias("int")); if (t...
20
by: pinkfloydhomer | last post by:
Is it well-defined and portable to do something like: typedef struct { int type; char c; } S1; typedef struct {
22
by: mp | last post by:
i have a python program which attempts to call 'cls' but fails: sh: line 1: cls: command not found i tried creating an alias from cls to clear in .profile, .cshrc, and /etc/profile, but none...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
15
by: jacob navia | last post by:
Recently, we had a very heated thread about GC with the usual arguments (for, cons, etc) being exchanged. In one of those threads, we came into the realloc problem. What is the realloc...
22
by: Daniel Rucareanu | last post by:
I have the following script: function Test(){} Test.F = function(){} Test.F.FF = function(){} Test.F.FF.FFF = function(){} Test.F.FF.FFF.FFFF = function(){} //var alias = function(){}; var...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...

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.