[freetds] too many casts, sire
Lowden, James K
LowdenJK at bernstein.com
Tue Apr 13 11:25:45 EDT 2004
> From: Thompson, Bill D (London) [mailto:bill_d_thompson at ml.com]
> Sent: April 13, 2004 9:04 AM
> I taught myself C on an IBM RT PC 6150 (anyone else remember
> those ?) some 17 years ago.
Sure I remember them. Never used one, though.
> Maybe on that first version of AIX, it was necessary to cast
> like that.
> I'll endeavour to bring myself into the 21st century
> though...perhaps one day I'll even learn C++ ....
"In theory, there's no difference between theory and practice; in practice, there is."
Standards are one thing. I was really wondering if these casts were (still) necessary for the code to compile on some holdover from the ancien regime. Sometimes we have casts just to quell the compiler's warning system, which is bad enough (but not entirely wrong), but adding a cast where no compiler needs it is surely service to no one.
The language evolves, for sure. I remember in 1994 I was porting some VMS C to C++ on what they called "Daytona", later known as NT 3.5. The C I knew was K&R, and I couldn't believe it when I found structs being copied by assignment (instead of memcpy). It earned me a "welcome to the '90s" from my team mates. And it compiled fine as C++.
> > -----Original Message-----
> > From: James K. Lowden [SMTP:jklowden at schemamania.org]
> > Sent: 07 April 2004 04:16
> > To: TDS Development Group
> > Subject: [freetds] too many casts, sire
> > http://www.fiendish.demon.co.uk/c/casting.html
> > http://www.vmunix.com/~gabor/c/draft.html#18.104.22.168
> > I came across this line in bcp.c (reformatted):
> > if ((curptr->nextptr =
> > (struct fflist *) malloc(sizeof(struct fflist)))
> > == (struct fflist *) NULL)
> > ANSI C says:
> > 1. It's never necessary to cast to compare to a null pointer.
> > 2. It's never necessary to cast void* for assignment.
> > That tells me this could as well read:
> > if ((curptr->nextptr =
> > malloc(sizeof(struct fflist))) == NULL)
> > which I can actually read. Is there any reason not to
> simplify this? Is
> > anyone really using a malloc() that returns char* in 2004?
> (The casting
> > of NULL is just plain egregious, not merely old fashioned.)
> > --jkl
> > _______________________________________________
> > FreeTDS mailing list
> > FreeTDS at lists.ibiblio.org
> > http://lists.ibiblio.org/mailman/listinfo/freetds
> If you are not an intended recipient of this e-mail, please notify
> the sender, delete it and do not read, act upon, print, disclose,
> copy, retain or redistribute it.
> Click here for important additional terms relating to this e-mail.
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
The information contained in this transmission may contain privileged and confidential information and is intended only for the use of the person(s) named above. If you are not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you are not the intended recipient, please contact the sender immediately by reply e-mail and destroy all copies of the original message. Please note that we do not accept account orders and/or instructions by e-mail, and therefore will not be responsible for carrying out such orders and/or instructions.
If you, as the intended recipient of this message, the purpose of which is to inform and update our clients, prospects and consultants of developments relating to our services and products, would not like to receive further e-mail correspondence from the sender, please "reply" to the sender indicating your wishes. In the U.S.: 1345 Avenue of the Americas, New York, NY 10105.
More information about the FreeTDS