Article View: alt.msdos.programmer
Article #1211Re: typecasting preferences
From: Max Waterman
Date: Thu, 18 Apr 1996 12:16
Date: Thu, 18 Apr 1996 12:16
55 lines
2119 bytes
2119 bytes
Tarang Deshpande wrote:
>
> HASDI RODZMANN HASHIM wrote:
> >
> > If you have a choice, do you want the parethesis pair over the caster
> > (C-style) or over the castee (Pascal-style)? eg...
> >
> > a = (int)b; /* cast to int */
> > a = int(b); /* allowable in C++ */
> >
>
> I would prefer the Pascal style where the parenthesis go around the
> thing being casted. This is so that the cast looks like a function
> and it then seems consistent when overriding the cast operator.
Why do you want it to look like a function? This makes it misleading.
What do you mean by 'overriding the cast operator'?
In C you can have a type of any name, so it is very misleading to have a
cast look like a function. On my compiler it flags it as a syntax error
anyway (is this the same with others?) - so I am quite happy that this
isn't allowed. Consider the following :
#include <stdio.h>
typedef double sin;
.
.
. loads of source lines....
.
.
int main( void )
{
float f = 3.123485;
printf( "%f", sin(f) );
}
looks like sin(f) is taking the sine of f but in fact it is meant to
cast it to a double.
Even if it did compile, I wouldn't pass this in a code inspection.
Unless you can give me a good reason this is useful.
Max.
--
___ mailto:dwater@hursley.ibm.com
/ / / _ / / _ __ __ _ __ _
/ / / /_/ |/ / / / /_/ / /_ /_/ / / / /_/ /| /
/ / / / / /| /_/_/ / / / /_ / | / / / / / / |/
Technical Details
Message-ID:
<3176329E.41C6@wight.hursley.ibm.com>Path:
arc1-ca.pugleaf.net!hursley.ibm.com!newsReferences:
<4l020g$i9j@srvr1.engin.umich.edu> <3173E842.7D17@willows.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!hursley.ibm.com!news From: Max Waterman <dwater@wight.hursley.ibm.com> Newsgroups: alt.msdos.programmer,comp.lang.c,comp.lang.pascal.misc Subject: Re: typecasting preferences Date: Thu, 18 Apr 1996 13:16:30 +0100 Organization: IBM UK Laboratories Ltd. Message-ID: <3176329E.41C6@wight.hursley.ibm.com> References: <4l020g$i9j@srvr1.engin.umich.edu> <3173E842.7D17@willows.com> Reply-To: dwater@hursley.ibm.com NNTP-Posting-Host: wight.hursley.ibm.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 2.01 (X11; I; AIX 2)