Re: coding conventions: pointers, structures, and unions

From: Alan Balmer (albalmer_at_att.net)
Date: 10/16/03


Date: Wed, 15 Oct 2003 16:42:50 -0700

On 15 Oct 2003 16:32:32 -0700, nzanella@cs.mun.ca (Neil Zanella)
wrote:

>pete <pfiland@mindspring.com> wrote in message
>
>> For anyone not modifying code,
>> I don't think that any meaningful understanding,
>> comes from knowing that you.your_name is a structure
>> member rather than a union member.
>
>Since I am not personally a big fan of Hungarian notation, I mostly
>agree with you, but suppose I have something like:
>
>union {
> int x;
> char c;
>} foo;
>
>and then later on in the source code there is a line that reads:
>
>foo.x = 1;
>
>Later on someone decides to add the following line to the code,
>
>foo.c = 'a';
>
>not realizing that foo is a union and not a structure. Suddenly the
>whole program misbehaves, and the compiler doesn't catch it: it's a
>run time error. One possible course of action would have been in
>this case to replace the union with a struct, since both fields
>were needed at the same time.

Why would someone be adding an assignment statement without knowing
what kind of object he was assigning to? He might just as well have
done

d = 'c';

where d is declared double. Same kind of problem, and nothing to do
with the difference between structs and unions.

>
>I have never made the above mistake, but I've seen it happen.
>Hence if Hungarian notation is being used for ALL variables
>then you might as well have a rule for unions. As an aside,
>Hungarian notation is not something I particularly like. It
>may be OK for some pointers in some cases, but I wouldn't
>say it's worthwhile using it for everything, (unless you
>really have to, i.e., someone makes you use it).
>
>Regards,
>
>Neil

--
Al Balmer
Balmer Consulting
removebalmerconsultingthis@att.net


Relevant Pages

  • Re: OT: Kinda prying here, but what does everyone do for a living?
    ... Yes, that does hit home, looks alot like the work i do. ... union member am in a fight to keep my trade alive Eric. ... The union trains me, my contract insures that the gear to do the job ... i am a trainer. ...
    (rec.games.pinball)
  • Re: C Offsetof
    ... I have following structures and union ... int a; ... union Member *mem; ...
    (comp.lang.c)
  • Re: It is official...
    ... transmitting rage. ... ...I am a union member. ... entering into certain types of agreements with unions. ... I'm not a union member. ...
    (rec.sport.football.college)
  • Re: Trying to form a Union
    ... Sounds like the counter view point is not a union member. ... Thats what managers are paid to do, ... I am surprised that anyone buying a business would even include union ...
    (rec.crafts.metalworking)
  • Re: Trying to form a Union
    ... Sounds like the counter view point is not a union member. ... manager and could not retain Union membership. ... There is an increasing number of employers who see the threat from third ...
    (rec.crafts.metalworking)