435,098 Members | 1,950 Online
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

# checking double for Inf or NaN - how?

 P: n/a 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 Replies

 P: n/a "Martin Jørgensen" 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

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a 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 #include #include 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 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

 P: n/a 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) soI 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

 P: n/a 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 andone that checks for NaN, if there's any difference? I didn't reallyunderstood 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) soI 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

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a jacob navia 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 San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. May 19 '06 #15

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a In article , Richard Heathfield writesjacob 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 factoStandard, 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 dayappears to be some way off - the GNU people have shied away from fullconformance 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 C89features. Neither, it appears, are they wanted by the majority. -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ May 19 '06 #21

 P: n/a In article <44***********************@news.wanadoo.fr>, jacob navia writesRichard 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 isnot mine anyway. There are people that will stay in the past, longingfor 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 eachimplementation".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

 P: n/a In article , Richard Heathfield writesjacob 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 ahosted 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 specificallymentioned that a freestanding implementation is targeted). If the platformmatters, well, there are other newsgroups where such discussions can beheld. 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

 P: n/a In article , Richard Heathfield 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

 P: n/a In article , Richard Tobin writesIn article ,Richard Heathfield 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

 P: n/a Richard Tobin a écrit : In article , Richard Heathfield wrote:>There are C99 compilers under windows, and under Unix.Those are the operating systems mentioned in the original poster'smessage.He also mentioned the Mac. Macs run unix these days. Yes but he is using a mac vintage 1989... :-) jacob May 19 '06 #26

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a 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

 P: n/a Chris Hills said: In article , Richard Heathfield writesjacob 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 factoStandard, 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 dayappears to be some way off - the GNU people have shied away from fullconformance 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 C89features. 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

 P: n/a Richard Tobin said: In article , Richard Heathfield 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

 P: n/a 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

 P: n/a In article , Richard Heathfield wrote:Chris Hills said: In article , Richard Heathfield 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

 P: n/a In article , Richard Heathfield 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, becauseit 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

 P: n/a In article in*****@invalid.invalid writes: Richard Tobin said: In article , Richard Heathfield 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

 P: n/a Chris Hills writes: In article , Richard Heathfield writesjacob 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 factoStandard, 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 dayappears to be some way off - the GNU people have shied away from fullconformance 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 C89features. 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 San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. May 19 '06 #37

 P: n/a "Keith Thompson" wrote in message news:ln************@nuthaus.mib.org... Chris Hills writes: In article , Richard Heathfield writesjacob 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 factoStandard, 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

 P: n/a "Richard Heathfield" 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

 P: n/a "Chris Hills" wrote in message news:sf**************@phaedsys.demon.co.uk... In article , Richard Heathfield writesjacob 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 ahosted 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

 P: n/a "jacob navia" 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

 P: n/a Malcolm a écrit : "Richard Heathfield" wrotepete said:Richard Heathfield wrote: C99 features are, quite simply, not even remotely as portable as C89features.I like the added restrictions of C99, such as no implicit intand requiring protypes for all functions.Likewise. Shame about the return value from main, but I stick it inanyway,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

 P: n/a On 2006-05-20, jacob navia 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

 P: n/a "jacob navia" wrote Malcolm a écrit : "Richard Heathfield" 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

 P: n/a Malcolm said: "jacob navia" wrote Malcolm a écrit : "Richard Heathfield" 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

 P: n/a "Richard Heathfield" wrote in message news:0K******************************@bt.com... Malcolm said: "jacob navia" wrote Malcolm a écrit : "Richard Heathfield" 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

 P: n/a Richard Heathfield wrote: Malcolm said: "jacob navia" wrote Malcolm a écrit : "Richard Heathfield" 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

 P: n/a Default User said: Richard Heathfield wrote: Malcolm said: > "jacob navia" wrote >> Malcolm a écrit : >>> "Richard Heathfield" 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

 P: n/a In article <0K******************************@bt.com>, Richard Heathfield wrote: Malcolm said: "jacob navia" wrote Malcolm a écrit : "Richard Heathfield" wroteNo, 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

 P: n/a Gordon Burditt wrote: In article <0K******************************@bt.com>, Richard Heathfield wrote: Malcolm said: "jacob navia" wrote Malcolm a écrit :> "Richard Heathfield" 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

55 Replies

### This discussion thread is closed

Replies have been disabled for this discussion.