Re: coding conventions: pointers, structures, and unions
From: Alan Balmer (albalmer_at_att.net)
Date: 10/16/03
- Next message: Richard Heathfield: "Re: why still use C?"
- Previous message: Richard Heathfield: "Re: why still use C?"
- In reply to: Neil Zanella: "Re: coding conventions: pointers, structures, and unions"
- Next in thread: Jeffrey D. Smith: "Re: coding conventions: pointers, structures, and unions"
- Reply: Jeffrey D. Smith: "Re: coding conventions: pointers, structures, and unions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Richard Heathfield: "Re: why still use C?"
- Previous message: Richard Heathfield: "Re: why still use C?"
- In reply to: Neil Zanella: "Re: coding conventions: pointers, structures, and unions"
- Next in thread: Jeffrey D. Smith: "Re: coding conventions: pointers, structures, and unions"
- Reply: Jeffrey D. Smith: "Re: coding conventions: pointers, structures, and unions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|