comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: YACT (Yet Another C Trap)
Date: Mon, 30 Aug 2010 00:52:26 -0700 (PDT)
Date: 2010-08-30T00:52:26-07:00	[thread overview]
Message-ID: <8c1b1776-6293-4663-ae65-32c667c3acc3@s15g2000yqm.googlegroups.com> (raw)
In-Reply-To: Pine.LNX.4.64.1008301014490.28149@medsec1.medien.uni-weimar.de

On 30 Sie, 10:21, stefan-lu...@see-the.signature wrote:

> I tried it out. The above example gives an error. But the following
> program compiles without warnings with gcc:
>
> #include <stdio.h>
> int main (int argc, char **argv)
> { float x;
>
>     x = 12,3;

> Is this a language flaw of C, or a bug in gcc?

It is a language flaw for two reasons: one is that the language should
not allow you to initialize floating-point values with integers and
the other is that the comma operator for fundamental types is nonsense
[*]. :-)

[*] But there are quite nice ways to use it for custom types.

In any case, the above code violates the coding standard that
discourages the use of unnamed numeric constants. Constants should be
named (with notable exception of 0 and 1), which would bring you back
to compile-time error. You might still argue that the need for such a
coding standard indicates a flaw in the language anyway.

Note that the above problem has many more interesting implications,
especially when combined with other flaws:

float f = 10.0f;

f = f * 1,5;

Go figure what it does (and I can bet that your guess will be
wrong). ;-)

--
Maciej Sobczak * http://www.inspirel.com

YAMI4 - Messaging Solution for Distributed Systems
http://www.inspirel.com/yami4



  reply	other threads:[~2010-08-30  7:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-21  9:32 YACT (Yet Another C Trap) mockturtle
2010-08-27  4:13 ` Shark8
2010-08-29 20:55 ` Maciej Sobczak
2010-08-30  8:21   ` stefan-lucks
2010-08-30  7:52     ` Maciej Sobczak [this message]
2010-08-30  8:28     ` stefan-lucks
2010-08-30 10:13       ` Peter C. Chapin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox