473,473 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

checking double for Inf or NaN - how?

Hi,

I found the code below from
http://www.blitzbasic.com/Community/...hp?topic=55633

------
' Check if number is finite.
Local u:Double = 2 ' also works for floats

For Local n = 1 To 12
Print isfinite(u) + " " + u
u :* u
Next

Print
Print "What about NaN?"
Print

u = u - u
Print isfinite(u) + " " + u
Function isfinite( x:Double ) ' assumes Intel byte order

Const EXP_BITS = %01111111111100000000000000000000

Local bits = ( Int Ptr Varptr x )[1] ' [0] for Mac?

Return ( bits & EXP_BITS ) <> EXP_BITS ' exponent is all 1s for
infinity or NaN

End Function
------

I need something like that - but the author writes that "This is intel
only. Anybody want to make it multiplatform? It shouldn't be difficult,
but I don't have a Mac".

The code above doesn't look like "standard C" to me... But I would like
this function to work *preferable* under both linux, mac and windows
pc's....

My guess is that the code should be changed to something like:

int(double testval)
{
Const EXP_BITS = %01111111111100000000000000000000

return (testval && EXP_BITS); /* returns either 0 or 1 ? */
}

But I guess EXP_BITS is completely wrong defined, so how to make it work
- and are there better existing ways to check for Inf or NaN???

It would be nice with 2 functions: One that tests for plus/minus Inf and
one that checks for NaN, if there's any difference? I didn't really
understood the bit-pattern-difference between NaN and Inf...
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 18 '06 #1
55 8254

"Martin Jørgensen" <un*********@spam.jay.net> wrote in message
news:lb************@news.tdc.dk...
Hi,

I found the code below from
http://www.blitzbasic.com/Community/...hp?topic=55633

------
' Check if number is finite.
Local u:Double = 2 ' also works for floats

For Local n = 1 To 12
Print isfinite(u) + " " + u
u :* u
Next

Print
Print "What about NaN?"
Print

u = u - u
Print isfinite(u) + " " + u
Function isfinite( x:Double ) ' assumes Intel byte order

Const EXP_BITS = %01111111111100000000000000000000

Local bits = ( Int Ptr Varptr x )[1] ' [0] for Mac?

Return ( bits & EXP_BITS ) <> EXP_BITS ' exponent is all 1s for infinity
or NaN

End Function
------

I need something like that - but the author writes that "This is intel
only. Anybody want to make it multiplatform? It shouldn't be difficult,
but I don't have a Mac".

The code above doesn't look like "standard C" to me... But I would like
this function to work *preferable* under both linux, mac and windows
pc's....

My guess is that the code should be changed to something like:

int(double testval)
{
Const EXP_BITS = %01111111111100000000000000000000

return (testval && EXP_BITS); /* returns either 0 or 1 ? */
}

But I guess EXP_BITS is completely wrong defined, so how to make it work -
and are there better existing ways to check for Inf or NaN???

It would be nice with 2 functions: One that tests for plus/minus Inf and
one that checks for NaN, if there's any difference? I didn't really
understood the bit-pattern-difference between NaN and Inf...


The source snippet might look different to you than me, but it seems to be
missing about ten tokens in order to be C. joe
May 18 '06 #2
Martin Jørgensen wrote:
-snip-
It would be nice with 2 functions: One that tests for plus/minus Inf and
one that checks for NaN, if there's any difference? I didn't really
understood the bit-pattern-difference between NaN and Inf...


Basically I have a variable that contains -1.#IND00000000000...
according to MS visual studio 2005... I thought that this was (-inf) so
I made a check:

....
if( val < 0)
do something <- never got here....

I hope somebody can figure this out?
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 18 '06 #3
Martin Jørgensen wrote:
-snip-
understood the bit-pattern-difference between NaN and Inf...


Addition: You can generate -1.#IND000000... by:

#include math.h

....
var = sqrt (-10);
....

var = -1.#IND000000.., according to MS visual studio 2005 (just in case
somebody wants to try it out).
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 18 '06 #4

Martin Jørgensen wrote:
Martin Jørgensen wrote:
-snip-
It would be nice with 2 functions: One that tests for plus/minus Inf and
one that checks for NaN, if there's any difference? I didn't really
understood the bit-pattern-difference between NaN and Inf...


Basically I have a variable that contains -1.#IND00000000000...
according to MS visual studio 2005... I thought that this was (-inf) so
I made a check:

...
if( val < 0)
do something <- never got here....

I hope somebody can figure this out?
Martin Jørgensen


The IEEE floating point standard says that any comparison
in which one operand is a NaN should evaluate to FALSE.
So the following counter-intuitive test meets your needs:

if (val == val)
do_nothing ( );
else
report_NaN (val);

unless an over-eager (and incorrect) compiler optimises
half of it away . . .
--

May 18 '06 #5
Martin Jørgensen wrote:
Basically I have a variable that contains -1.#IND00000000000...
according to MS visual studio 2005...
I thought that this was (-inf) so
I made a check:

...
if( val < 0)
do something <- never got here....

I hope somebody can figure this out?


exp(DBL_MAX) is a range error.
sqrt(-1) is a domain error.

/* BEGIN new.c */

#include <math.h>
#include <float.h>
#include <stdio.h>

int main(void)
{
double x = -exp(DBL_MAX);
double y = sqrt(-1);

printf("-exp(DBL_MAX) is %f\n", x);
printf("sqrt(-1) is %f\n", y);
return 0;
}

/* END new.c */
N869
7.12.1 Treatment of error conditions
[#1] The behavior of each of the functions in <math.h> is
specified for all representable values of its input
arguments, except where stated otherwise.
[#2] For all functions, a domain error occurs if an input
argument is outside the domain over which the mathematical
function is defined. The description of each function lists
any required domain errors; an implementation may define
additional domain errors, provided that such errors are
consistent with the mathematical definition of the
function.182) On a domain error, the function returns an
implementation-defined value; whether the integer expression
errno acquires the value EDOM is implementation-defined.
[#3] Similarly, a range error occurs if the mathematical
result of the function cannot be represented in an object of
the specified type, due to extreme magnitude. A floating
result overflows if the magnitude of the mathematical result
is finite but so large that the mathematical result cannot
be represented, without extraordinary roundoff error, in an
object of the specified type. If a floating result
overflows and default rounding is in effect, or if the
mathematical result is an exact infinity (for example
log(0.0)), then the function returns the value of the macro
HUGE_VAL, HUGE_VALF, or HUGE_VALL according to the return
type, with the same sign as the correct value of the
function; whether errno acquires the value ERANGE when a
range error occurs is implementation-defined. The result
underflows if the magnitude of the mathematical result is so
small that the mathematical result cannot be
represented, without extraordinary roundoff error, in an
object of the
specified type. If the result underflows, the function
returns a value whose magnitude is no greater than the
smallest normalized positive number in the specified type
and is otherwise implementation-defined; whether errno
acquires the value ERANGE is implementation-defined.
--
pete
May 18 '06 #6
pete wrote:
Martin Jørgensen wrote:

Basically I have a variable that contains -1.#IND00000000000...
according to MS visual studio 2005...
I thought that this was (-inf) so
I made a check:

...
if( val < 0)
do something <- never got here....

I hope somebody can figure this out?

exp(DBL_MAX) is a range error.
sqrt(-1) is a domain error.

-snip-

Yes, thanks but you're only printing out the values using printf(). You
didn't make the if-test...
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 18 '06 #7
bert wrote:
Martin Jørgensen wrote:
Martin Jørgensen wrote:
-snip-

It would be nice with 2 functions: One that tests for plus/minus Inf and
one that checks for NaN, if there's any difference? I didn't really
understood the bit-pattern-difference between NaN and Inf...


Basically I have a variable that contains -1.#IND00000000000...
according to MS visual studio 2005... I thought that this was (-inf) so
I made a check:

...
if( val < 0)
do something <- never got here....

I hope somebody can figure this out?
Martin Jørgensen

The IEEE floating point standard says that any comparison
in which one operand is a NaN should evaluate to FALSE.
So the following counter-intuitive test meets your needs:

if (val == val)
do_nothing ( );
else
report_NaN (val);


Ok, thanks a lot - it works here and it was a lot easier than I
feared... And how do I check for plus/minus inf ?
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 18 '06 #8
Martin Jørgensen a écrit :
Hi,

I found the code below from
http://www.blitzbasic.com/Community/...hp?topic=55633

------
' Check if number is finite.
Local u:Double = 2 ' also works for floats

For Local n = 1 To 12
Print isfinite(u) + " " + u
u :* u
Next

Print
Print "What about NaN?"
Print

u = u - u
Print isfinite(u) + " " + u
Function isfinite( x:Double ) ' assumes Intel byte order

Const EXP_BITS = %01111111111100000000000000000000

Local bits = ( Int Ptr Varptr x )[1] ' [0] for Mac?

Return ( bits & EXP_BITS ) <> EXP_BITS ' exponent is all 1s for
infinity or NaN

End Function
------

I need something like that - but the author writes that "This is intel
only. Anybody want to make it multiplatform? It shouldn't be difficult,
but I don't have a Mac".

The code above doesn't look like "standard C" to me... But I would like
this function to work *preferable* under both linux, mac and windows
pc's....

My guess is that the code should be changed to something like:

int(double testval)
{
Const EXP_BITS = %01111111111100000000000000000000

return (testval && EXP_BITS); /* returns either 0 or 1 ? */
}

But I guess EXP_BITS is completely wrong defined, so how to make it work
- and are there better existing ways to check for Inf or NaN???

It would be nice with 2 functions: One that tests for plus/minus Inf and
one that checks for NaN, if there's any difference? I didn't really
understood the bit-pattern-difference between NaN and Inf...
Best regards / Med venlig hilsen
Martin Jørgensen


Standard C has several functions for this:
1) isfinite: returns true if its argument is finite
2) isinf: returns true if its argument is infinite
3) isnormal: returns true if its argument is normal
4) fpclassify returns the type of its argument.

See the documentation of your compiler system.

P.S. This will work in standard C, not in Visual Studio.
May 18 '06 #9
jacob navia wrote:
-snip-
Standard C has several functions for this:
1) isfinite: returns true if its argument is finite
2) isinf: returns true if its argument is infinite
3) isnormal: returns true if its argument is normal
4) fpclassify returns the type of its argument.

See the documentation of your compiler system.
Ok.
P.S. This will work in standard C, not in Visual Studio.


Is visual studio 2005 not standard C? I think I disabled something
that's on by default so I think it understands standard C at least... At
least I've had no problems yet with standard C on it (or is it ANSI C?
Don't know if there's any difference)....
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 18 '06 #10
Martin Jørgensen said:
jacob navia wrote:
-snip-
Standard C has several functions for this:
1) isfinite: returns true if its argument is finite
2) isinf: returns true if its argument is infinite
3) isnormal: returns true if its argument is normal
4) fpclassify returns the type of its argument.

See the documentation of your compiler system.


Ok.
P.S. This will work in standard C, not in Visual Studio.


Is visual studio 2005 not standard C?


Yes and no. VStudio conforms to ISO/IEC 9899:1990 (when you "disable
Microsoft extensions" in the project settings), modulo some trivial and
much-unused dark corners of the language. (Never come across these myself
AFAICR, but people here in clc have occasionally waxed lyrical on the
subject.)

But it doesn't conform to ISO/IEC 9899:1999, which is what you'd need if you
wanted to use Jacob Navia's suggestions. Having said that, almost no C
compilers conform to that later spec - and so, even if VStudio did give you
access to them, your code would still not be portable.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 18 '06 #11
Richard Heathfield wrote:
Martin Jørgensen said: -snip-
Is visual studio 2005 not standard C?

Yes and no. VStudio conforms to ISO/IEC 9899:1990 (when you "disable
Microsoft extensions" in the project settings), modulo some trivial and


Exactly! That is what I did (disabled those stupid extensions).
much-unused dark corners of the language. (Never come across these myself
AFAICR, but people here in clc have occasionally waxed lyrical on the
subject.)

But it doesn't conform to ISO/IEC 9899:1999, which is what you'd need if you
wanted to use Jacob Navia's suggestions. Having said that, almost no C
compilers conform to that later spec - and so, even if VStudio did give you
access to them, your code would still not be portable.


isinf and isfinite looks to me like they also exists under unix, so
doesn't that mean it would probably be portable?
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
May 18 '06 #12
Martin Jørgensen said:
isinf and isfinite looks to me like they also exists under unix, so
doesn't that mean it would probably be portable?


That depends entirely on your definition of "portable". :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 18 '06 #13
Martin Jørgensen a écrit :
Richard Heathfield wrote:
Martin Jørgensen said:


-snip-
Is visual studio 2005 not standard C?


Yes and no. VStudio conforms to ISO/IEC 9899:1990 (when you "disable
Microsoft extensions" in the project settings), modulo some trivial and

Exactly! That is what I did (disabled those stupid extensions).
much-unused dark corners of the language. (Never come across these
myself AFAICR, but people here in clc have occasionally waxed lyrical
on the subject.)

But it doesn't conform to ISO/IEC 9899:1999, which is what you'd need
if you wanted to use Jacob Navia's suggestions. Having said that,
almost no C compilers conform to that later spec - and so, even if
VStudio did give you access to them, your code would still not be
portable.

isinf and isfinite looks to me like they also exists under unix, so
doesn't that mean it would probably be portable?
Best regards / Med venlig hilsen
Martin Jørgensen


Visual studio conforms to the obsolete C standard of 1989.
It has:
isnan(double)
isnanf(float)
finitef(float)
finite(double)

Those functions can solve your problem too.

May 19 '06 #14
jacob navia <ja***@jacob.remcomp.fr> writes:
[...]
Visual studio conforms to the obsolete C standard of 1989.
It has:
isnan(double)
isnanf(float)
finitef(float)
finite(double)

Those functions can solve your problem too.


To be clear, the C89/C90 standard doesn't define those functions.
(I won't comment on whether the C89/C90 standard is "obsolete".)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 19 '06 #15
jacob navia said:
Visual studio conforms to the obsolete C standard of 1989.


The 1989 Standard is far from obsolete. It is still the current de facto
Standard, and will remain so until C99 is widely implemented. That day
appears to be some way off - the GNU people have shied away from full
conformance to C99, and Microsoft have ignored it completely.

The C Standard is of no value unless it enables us to write portable code.
C99 features are, quite simply, not even remotely as portable as C89
features.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 19 '06 #16
Richard Heathfield a écrit :
jacob navia said:

Visual studio conforms to the obsolete C standard of 1989.

The 1989 Standard is far from obsolete. It is still the current de facto
Standard, and will remain so until C99 is widely implemented. That day
appears to be some way off - the GNU people have shied away from full
conformance to C99,


The issues with gcc are VERY minor. It is a good C99 implementation, and
can be used without any problems.

and Microsoft have ignored it completely.

Yes

The C Standard is of no value unless it enables us to write portable code.


This is your opinion. Your are entitled to it Mr Heathfield, but it is
not mine anyway. There are people that will stay in the past, longing
for the lost "golden times"...

"Portability" for you means "taking the worst features of each
implementation".

There are C99 compilers under windows, and under Unix.
May 19 '06 #17
jacob navia said:
There are C99 compilers under windows, and under Unix.


ROTFL! Well, that's all right then!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 19 '06 #18
Richard Heathfield a écrit :
jacob navia said:

There are C99 compilers under windows, and under Unix.

ROTFL! Well, that's all right then!


Those are the operating systems mentioned in the original poster's
message.

You speak about "portability", as it was necessary for every piece of
code to be potentially portable to all possible machines. This is mostly
never the case. Many people do not care at all if their code can run
without modifications at some embedded system with a 15 year old
compiler you see?

Some code running with visual studio or under a Mac OSx or similar
will make so many hidden assumptions about RAM size, disk space, etc etc
that it will NEVER run in the "System X" running in the toaster
with 16k of ram.

So What?

May 19 '06 #19
jacob navia said:
Richard Heathfield a écrit :
jacob navia said:

There are C99 compilers under windows, and under Unix.

ROTFL! Well, that's all right then!


Those are the operating systems mentioned in the original poster's
message.


He also mentioned the Mac.
You speak about "portability", as it was necessary for every piece of
code to be potentially portable to all possible machines.


The general assumption in comp.lang.c is that the code is targeted at a
hosted implementation of unknown provenance (unless it is specifically
mentioned that a freestanding implementation is targeted). If the platform
matters, well, there are other newsgroups where such discussions can be
held.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 19 '06 #20
In article <Qo********************@bt.com>, Richard Heathfield
<in*****@invalid.invalid> writes
jacob navia said:
Visual studio conforms to the obsolete C standard of 1989.
The 1989 Standard is far from obsolete. It is still the current de facto
Standard,


I think you mean ISO 9899:1990 + A1 and the TC's aka C95

C89 is a local US standard that was superseded by the ISO standard in
1990.
and will remain so until C99 is widely implemented. That day
appears to be some way off - the GNU people have shied away from full
conformance to C99, and Microsoft have ignored it completely.

The C Standard is of no value unless it enables us to write portable code.
I don't agree there. There are few truly portable apps. However I agree
that the c standard is of little use unless the language as defined in
the standard is of use and implimentable in the majority of compilers.
Or the majority of it implimentable in All compilers.
C99 features are, quite simply, not even remotely as portable as C89
features.


Neither, it appears, are they wanted by the majority.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 19 '06 #21
In article <44***********************@news.wanadoo.fr>, jacob navia
<ja***@jacob.remcomp.fr> writes
Richard Heathfield a écrit :
jacob navia said:

The C Standard is of no value unless it enables us to write portable code.
This is your opinion. Your are entitled to it Mr Heathfield, but it is
not mine anyway. There are people that will stay in the past, longing
for the lost "golden times"...


In some cases fools rush in where angles fear to tread.

The problem is AFAICS that C99 contains things that are broken and not a
good idea which is why the compiler vendors did not rush to implement
it. Neither have the majority of users demanded them.

If you look at the recent argument about the "Spawn of Satan M$" who are
working with ECMA on C++/CLI (also C#) for desktop use and then note
that MISRA took C90 as a base for embedded use. Put that against the
fact that several of the ISO C panel have said they regret several
features got into C99 you have to ask what is the point of C99?

It appears that the ISO standards have departed from industry usage and
practice. There are other "standards" being developed by the industry
that are in use or the de-facto standards.

ISO BASIC died whilst VB is widely used.

"Portability" for you means "taking the worst features of each
implementation".

There are C99 compilers under windows, and under Unix.


Very few but we have been here before. :-( Let's not argue that again.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 19 '06 #22
In article <S7******************************@bt.com>, Richard Heathfield
<in*****@invalid.invalid> writes
jacob navia said:
Richard Heathfield a écrit :
jacob navia said:
There are C99 compilers under windows, and under Unix.
ROTFL! Well, that's all right then!

Those are the operating systems mentioned in the original poster's
message.


He also mentioned the Mac.
You speak about "portability", as it was necessary for every piece of
code to be potentially portable to all possible machines.


The general assumption in comp.lang.c is that the code is targeted at a
hosted implementation


Only by some people.

The other thing to consider is that the majority of C implimentations
are more likely to be in the embedded space (there are probably at least
4 compilers for any embedded target and dozens of targets) since AFAIK
most desktop systems have moved to C++, C# and C++/CLI etc
of unknown provenance (unless it is specifically
mentioned that a freestanding implementation is targeted). If the platform
matters, well, there are other newsgroups where such discussions can be
held.


However the language as defined should be implimentable on the majority
of compilers/platforms or the majority of the language on all of the
compilers/platforms.

As I have said before if you only want to discus PURE ISO c (ie C99) on
a hosted target then you are very sorely limited.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 19 '06 #23
In article <S7******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
There are C99 compilers under windows, and under Unix.
Those are the operating systems mentioned in the original poster's
message.
He also mentioned the Mac.


Macs run unix these days.

-- Richard
May 19 '06 #24
In article <e4**********@pc-news.cogsci.ed.ac.uk>, Richard Tobin
<ri*****@cogsci.ed.ac.uk> writes
In article <S7******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
>There are C99 compilers under windows, and under Unix. Those are the operating systems mentioned in the original poster's
message.

He also mentioned the Mac.


Macs run unix these days.

-- Richard


AFAIK
OSX was developed from NEXT Step OS which was developed from BSD Unix.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

May 19 '06 #25
Richard Tobin a écrit :
In article <S7******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:

>There are C99 compilers under windows, and under Unix.
Those are the operating systems mentioned in the original poster's
message.


He also mentioned the Mac.

Macs run unix these days.


Yes but he is using a mac vintage 1989...

:-)

jacob
May 19 '06 #26
Richard Heathfield wrote:
C99 features are, quite simply, not even remotely as portable as C89
features.


I like the added restrictions of C99,
such as no implicit int
and requiring protypes for all functions.

C89 code, written with the additional restrcitions of C99,
is better formatted C89 code.

--
pete
May 19 '06 #27
Richard Heathfield wrote:

jacob navia said:

You speak about "portability",
as it was necessary for every piece of
code to be potentially portable to all possible machines.


That's just for code posted to the newsgroup.

The group is about the language,
not "your" implmentation,
("your", for all possible values of "you").

--
pete
May 19 '06 #28
jacob navia wrote:
"Portability" for you means "taking the worst features of each
implementation".


That is what it means.

The C programming language (the topic of the group),
is defined in terms of the abstract machine.

--
pete
May 19 '06 #29
pete wrote:

Richard Heathfield wrote:

jacob navia said:

You speak about "portability",
as it was necessary for every piece of
code to be potentially portable to all possible machines.


That's just for code posted to the newsgroup.

The group is about the language,
not "your" implmentation,
("your", for all possible values of "you").


I don't have a problem with posted code
that is for specific implementation defined situations
such as where CHAR_BIT equals eight and sizeof(int) equals four,
and as long as the implementation defined restrictions
for the code are completely specified, in the post.

I'm only interested in the name of a compiler
when the issue is
whether or not it is a conforming implementation.

--
pete
May 19 '06 #30
Chris Hills said:
In article <Qo********************@bt.com>, Richard Heathfield
<in*****@invalid.invalid> writes
jacob navia said:
Visual studio conforms to the obsolete C standard of 1989.


The 1989 Standard is far from obsolete. It is still the current de facto
Standard,


I think you mean ISO 9899:1990 + A1 and the TC's aka C95


Quite so. Shorthand, my dear chap, shorthand. (And, of course, I was echoing
JN's use of "1989".)
and will remain so until C99 is widely implemented. That day
appears to be some way off - the GNU people have shied away from full
conformance to C99, and Microsoft have ignored it completely.

The C Standard is of no value unless it enables us to write portable code.


I don't agree there. There are few truly portable apps.


I didn't say "apps". I said "code". Personally, I write a lot of portable
programs, but that's neither here nor there. The value of the Standard is
that it allows us to divide our application code into portable and
non-portable parts, so that only the non-portable part need be rewritten
for each port to a new platform. If this is done well, as much as 99% of a
GUI application can be ported without change (I've certainly experienced
this with a half-million-line set-top-box application, which had to be
ported to all manner of platforms, including those with weird CHAR_BITs and
the like).

The Standard helps us to divide the code appropriately. If the Standard is
not /implemented/ (sufficiently widely), though, there isn't much point in
paying attention to it. That is the position C99 is in.
C99 features are, quite simply, not even remotely as portable as C89
features.


Neither, it appears, are they wanted by the majority.


Right - so I see no reason to bother with C99 at all.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 19 '06 #31
Richard Tobin said:
In article <S7******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
>There are C99 compilers under windows, and under Unix. Those are the operating systems mentioned in the original poster's
message.

He also mentioned the Mac.


Macs run unix these days.


Well, they *can*, but that doesn't mean that all of them *do*. The OP
(rightly) did not say which OS he was running on his Mac. Rightly, because
it is irrelevant in this newsgroup.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 19 '06 #32
pete said:
Richard Heathfield wrote:
C99 features are, quite simply, not even remotely as portable as C89
features.


I like the added restrictions of C99,
such as no implicit int
and requiring protypes for all functions.


Likewise. Shame about the return value from main, but I stick it in anyway,
of course.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 19 '06 #33
In article <h6******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
Chris Hills said:
In article <Qo********************@bt.com>, Richard Heathfield
<in*****@invalid.invalid> writes
The C Standard is of no value unless it enables us to write portable code.


I don't agree there. There are few truly portable apps.


I didn't say "apps". I said "code".


Datum:
The code I'm currently working on at my day job breaks down as:
1399 lines of portable will-end-up-as-production code
349 lines of portable offline test drivers
60-ish lines of DLL entry points and interfacing for the live version

(The first two numbers came from wc -l, so include comments and
whitespace; the last is an estimate, since I don't have that code on
the laptop I'm using right now.)

It's not done yet, but most of the code that's yet to be written
(probably not more than another 100 lines or so; the part that does the
heavy lifting is done) will go in the first line in my summary.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca

The full rant is left as an exercise for the motivated reader.
--David Rush in comp.lang.scheme
May 19 '06 #34
In article <h6******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
Macs run unix these days.
Well, they *can*, but that doesn't mean that all of them *do*.
More than 99% of those still in use, I would guess. The newer ones
can't run pre-unix MacOS.
The OP
(rightly) did not say which OS he was running on his Mac. Rightly, because
it is irrelevant in this newsgroup.


I was not addressing the OP, just your implication that "mac" was not
covered by "unix".

-- Richard
May 19 '06 #35
In article <h6******************************@bt.com> in*****@invalid.invalid writes:
Richard Tobin said:
In article <S7******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote: ....
He also mentioned the Mac.


Macs run unix these days.


Well, they *can*, but that doesn't mean that all of them *do*.


Not even all of them *can*. And none of the Macs I have runs unix.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
May 19 '06 #36
Chris Hills <ch***@phaedsys.org> writes:
In article <Qo********************@bt.com>, Richard Heathfield
<in*****@invalid.invalid> writes
jacob navia said:
Visual studio conforms to the obsolete C standard of 1989.


The 1989 Standard is far from obsolete. It is still the current de facto
Standard,


I think you mean ISO 9899:1990 + A1 and the TC's aka C95

C89 is a local US standard that was superseded by the ISO standard in
1990.


Yes, but the 1989 ANSI standard and the 1990 ISO standard are
virtually identical; the only differences are the section numbers and
some non-normative introductory material. A conforming C89 compiler
is a conforming C90 compiler, and vice versa.

As for C95, that raises a (possibly) interesting question. Are there
any C implementations currently in significant use that support C90
but not C95? Does the use of features introduced in C95 make code
significantly non-portable?
and will remain so until C99 is widely implemented. That day
appears to be some way off - the GNU people have shied away from full
conformance to C99, and Microsoft have ignored it completely.

The C Standard is of no value unless it enables us to write portable code.


I don't agree there. There are few truly portable apps. However I agree
that the c standard is of little use unless the language as defined in
the standard is of use and implimentable in the majority of compilers.
Or the majority of it implimentable in All compilers.
C99 features are, quite simply, not even remotely as portable as C89
features.


Neither, it appears, are they wanted by the majority.


In my opinion, features defined by either the C90 or C99 standard are
perfectly appropriate for discussion here. (I don't quite share
Richard's disdain for C99.) On the other hand, it's also perfectly
appropriate to point out that certain features are defined in C99 but
not in C90 or C95, and that code that depends on C99 features is less
portable than code that doesn't. On this point, I strongly disagree
with jacob; C90 is *not* obsolete.

I'd be happier if C99 had caught on more widely, and C90 were
relegated to the same kind of historical discussion as pre-ANSI K&R C
(which is still a legitimate topic here). But that's not the reality,
and it's foolish to pretend that it is.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 19 '06 #37
"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
Chris Hills <ch***@phaedsys.org> writes:
In article <Qo********************@bt.com>, Richard Heathfield
<in*****@invalid.invalid> writes
jacob navia said:

Visual studio conforms to the obsolete C standard of 1989.

The 1989 Standard is far from obsolete. It is still the current de facto
Standard,


I think you mean ISO 9899:1990 + A1 and the TC's aka C95

C89 is a local US standard that was superseded by the ISO standard in
1990.


Yes, but the 1989 ANSI standard and the 1990 ISO standard are
virtually identical; the only differences are the section numbers and
some non-normative introductory material. A conforming C89 compiler
is a conforming C90 compiler, and vice versa.

As for C95, that raises a (possibly) interesting question. Are there
any C implementations currently in significant use that support C90
but not C95? Does the use of features introduced in C95 make code
significantly non-portable?


Yes to both. See:

http://www.dinkumware.com/conform_c.html

It's several years old now, but still remarkably accurate. Note that
C++98 requires C95, not just C90; very few Standard C++ libraries
conform in this area, however, because they depend on the underlying
C library to deliver the goods.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
May 19 '06 #38
"Richard Heathfield" <in*****@invalid.invalid> wrote
pete said:
Richard Heathfield wrote:
C99 features are, quite simply, not even remotely as portable as C89
features.


I like the added restrictions of C99, such as no implicit int
and requiring protypes for all functions.


Likewise. Shame about the return value from main, but I stick it in
anyway,
of course.

Implicit int was a fossil and it's time it went.
However prototypes are just a nuisance. There's some case for them in a
header file, where they describe the interface to the file, but the only
reason for them in other places is to allow the compiler to check arguments
on one pass. A modern compiler should be intelligent enough to do this
without a prototype to help it along.
--
www.personal.leeds.ac.uk/~bgy1mm


May 20 '06 #39

"Chris Hills" <ch***@phaedsys.org> wrote in message
news:sf**************@phaedsys.demon.co.uk...
In article <S7******************************@bt.com>, Richard Heathfield
<in*****@invalid.invalid> writes
jacob navia said:
Richard Heathfield a écrit :
jacob navia said:
>There are C99 compilers under windows, and under Unix.
ROTFL! Well, that's all right then!
Those are the operating systems mentioned in the original poster's
message.


He also mentioned the Mac.
You speak about "portability", as it was necessary for every piece of
code to be potentially portable to all possible machines.


The general assumption in comp.lang.c is that the code is targeted at a
hosted implementation


Only by some people.

The other thing to consider is that the majority of C implimentations
are more likely to be in the embedded space (there are probably at least
4 compilers for any embedded target and dozens of targets) since AFAIK
most desktop systems have moved to C++, C# and C++/CLI etc

Also at the other end.
Parallel machines use MPI (Message Passing Interface) these days as the
standard. It comes in C or, you've guessed, it, Fortran 77. So those are the
languages I use.
--
www.personal.leeds.ac.uk/~bgy1mm


May 20 '06 #40
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Richard Heathfield a écrit :
jacob navia said:


"Portability" for you means "taking the worst features of each
implementation".

That's inevitable. The convoy travels at the speed of the slowest ship.

--
www.personal.leeds.ac.uk/~bgy1mm
May 20 '06 #41
Malcolm a écrit :
"Richard Heathfield" <in*****@invalid.invalid> wrote
pete said:

Richard Heathfield wrote:
C99 features are, quite simply, not even remotely as portable as C89
features.

I like the added restrictions of C99, such as no implicit int
and requiring protypes for all functions.


Likewise. Shame about the return value from main, but I stick it in
anyway,
of course.


Implicit int was a fossil and it's time it went.
However prototypes are just a nuisance. There's some case for them in a
header file, where they describe the interface to the file, but the only
reason for them in other places is to allow the compiler to check arguments
on one pass. A modern compiler should be intelligent enough to do this
without a prototype to help it along.


Please think a bit Malcom.

To know the argument for a function without prototypes the compiler
should have the source code for all functions, including those in the
libraries the program is using. This would imply that the source code
for all the system would have to be processed, loaded into memory,
before any checks could be done.

This is completely impossible, so *some* type of prototype declaration
is needed. In Pascal you have the 'interface' declarations, in C# you
have a similar construct... etc!

May 20 '06 #42
On 2006-05-20, jacob navia <ja***@jacob.remcomp.fr> wrote:
Malcolm a écrit :
Implicit int was a fossil and it's time it went.
However prototypes are just a nuisance. There's some case for them in a
header file, where they describe the interface to the file, but the only
reason for them in other places is to allow the compiler to check arguments
on one pass. A modern compiler should be intelligent enough to do this
without a prototype to help it along.


Please think a bit Malcom.

To know the argument for a function without prototypes the compiler
should have the source code for all functions, including those in the
libraries the program is using. This would imply that the source code
for all the system would have to be processed, loaded into memory,
before any checks could be done.

This is completely impossible, so *some* type of prototype declaration
is needed. In Pascal you have the 'interface' declarations, in C# you
have a similar construct... etc!

Not to mention the fact that maintenance programmers want a prototype
to give them some idea of how a function works!

--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
Get your game faces on, because this is not a game.
May 20 '06 #43
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Malcolm a écrit :
"Richard Heathfield" <in*****@invalid.invalid> wrote

However prototypes are just a nuisance. There's some case for them in a
header file, where they describe the interface to the file, but the only
reason for them in other places is to allow the compiler to check
arguments on one pass. A modern compiler should be intelligent enough to
do this without a prototype to help it along.


Please think a bit Malcom.

To know the argument for a function without prototypes the compiler should
have the source code for all functions, including those in the libraries
the program is using. This would imply that the source code for all the
system would have to be processed, loaded into memory, before any checks
could be done.

This is completely impossible, so *some* type of prototype declaration is
needed. In Pascal you have the 'interface' declarations, in C# you have a
similar construct... etc!

The library should contain information about the signature of the functions
it contains.

The problem might be the weight of libraries without this feature, and no
way of retrieving information from them.
--
www.personal.leeds.ac.uk/~bgy1mm


May 21 '06 #44
Malcolm said:
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Malcolm a écrit :
"Richard Heathfield" <in*****@invalid.invalid> wrote


No, Richard Heathfield didn't write any of the stuff quoted in your article.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 21 '06 #45

"Richard Heathfield" <in*****@invalid.invalid> wrote in message
news:0K******************************@bt.com...
Malcolm said:
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Malcolm a écrit :
"Richard Heathfield" <in*****@invalid.invalid> wrote


No, Richard Heathfield didn't write any of the stuff quoted in your
article.

Think of the attribution lines as prototypes.
Initially I included the bit about implicit int, but then I realised that
jacob navia hadn't
mentioned that point, so I snipped it. But I forgot to update the
attributions.

That's the problem when you have information in two places at once.
--
www.personal.leeds.ac.uk/~bgy1mm

May 21 '06 #46
Richard Heathfield wrote:
Malcolm said:
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Malcolm a écrit :
"Richard Heathfield" <in*****@invalid.invalid> wrote


No, Richard Heathfield didn't write any of the stuff quoted in your
article.


You going to sue him?


Brian

May 21 '06 #47
Default User said:
Richard Heathfield wrote:
Malcolm said:
> "jacob navia" <ja***@jacob.remcomp.fr> wrote
>> Malcolm a écrit :
>>> "Richard Heathfield" <in*****@invalid.invalid> wrote


No, Richard Heathfield didn't write any of the stuff quoted in your
article.


You going to sue him?


I wasn't planning on it, no. I don't consider litigation to be the best way
to settle Usenet disagreements.

But having said that... with a name like Malcolm, he's probably Scottish -
so maybe I'll make an exception in his case. :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 21 '06 #48
In article <0K******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
Malcolm said:
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Malcolm a écrit :
"Richard Heathfield" <in*****@invalid.invalid> wrote


No, Richard Heathfield didn't write any of the stuff quoted in your article.


This is a perfect example of why attribution = misattribution,
and I didn't have anything to do with prior articles in this thread.

Also, this is off-topic for comp.lang.c. Is there a alt.flame.attributions?

Gordon L. Burditt
Jun 3 '06 #49
Gordon Burditt wrote:
In article <0K******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalid> wrote:
Malcolm said:
"jacob navia" <ja***@jacob.remcomp.fr> wrote
Malcolm a écrit :
> "Richard Heathfield" <in*****@invalid.invalid> wrote

No, Richard Heathfield didn't write any of the stuff quoted in your article.


This is a perfect example of why attribution = misattribution,
and I didn't have anything to do with prior articles in this thread.

Also, this is off-topic for comp.lang.c. Is there a alt.flame.attributions?


It was a simple case of forgetting to do a final snip after deleting the
last piece of Richard's text. It did not lead to major disputes the way
you claim.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Jun 3 '06 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Leo P. | last post by:
I am trying to write a spelling checker. Specifically the part that suggests words. From what I've read online, it seems like the preferred way to do this, is to find the double metaphone...
3
by: Guy Robinson | last post by:
I have the code below which parses an expression string and creates tokens. Can anyone suggest the best of error checking for things like: Valid variable only obj.attribute -whitespace allowed...
6
by: Web Developer | last post by:
Hi, I come across the term "type checking" very often in my readings on C++, and have never heard it in Java. Besides the simplistic answer that it checks the "type", what more does it mean? ...
6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
21
by: jacob navia | last post by:
Many compilers check printf for errors, lcc-win32 too. But there are other functions that would be worth to check, specially memset. Memset is used mainly to clear a memory zone, receiving a...
11
by: utab | last post by:
Dear all, I have a simple template to convert its argument to a string: template<typename T> string AtoStr(T t){ ostringstream sstrm; sstrm << t; return sstrm.str(); }
2
by: Mike | last post by:
Hello, Ok I have 2 classes in my project, one is the main form and one is a connection class, at a certain event on my main form a new instance is made of the connection class, and a reference...
4
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or...
1
by: powerej | last post by:
program is suppose to ask for an input from 1-8, if the user enters a number outside of this range than it will continue to ask until it does, something is wrong and i cant seem to figure it out, i...
9
by: pereges | last post by:
Hi, I'm trying to write a macro for the relative difference function which is used to check the close enough floating point values. Is this correct way to write it ? : #define max(x, y) ((x)...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.