Article View: comp.std.c
Article #4583Re: sizeof(1L) in preprocesor;How to tell sizeof(double)>sizeof(long) ?
From: Andreas Schwab
Date: Mon, 08 Jan 1996 12:58
Date: Mon, 08 Jan 1996 12:58
30 lines
1911 bytes
1911 bytes
In article <1996Jan5.094122.16151@sq.com>, msb@sq.com (Mark Brader) writes: |> Nobuhiko Katayama (nk@lns598.lns.cornell.edu) writes: |>> is there any portable way to tell whether |>> long is longer(shorter) than double in preprocessor stage ? |> I can't think of any way. |> You *can* use the various characteristics defined in <limits.h> and |> <float.h>, as explained in section 5.2.4.2 (2.2.4.2), to find out |> various information about the types. In particular, if what you |> really want is to choose whichever of the two types can hold the |> larger exact integer value, then in practice you need only do: |> #include <limits.h> |> #include <float.h> |> #if LONG_MAX * DBL_EPSILON > 1 |> typedef long mytype; |> #define mytype_format "%ld" /* for printf */ |> #else |> typedef double mytype; |> #define mytype_format "%f" |> #endif This doesn't work as floating point numbers aren't allowed in #if expressions. It must be written using a runtime check (which will probably optimized out by the compiler). -- Andreas Schwab "And now for something schwab@issan.informatik.uni-dortmund.de completely different"
Technical Details
Message-ID:
<vyzd98ug7w4.fsf@lamothe.informatik.uni-dortmund.de>Path:
arc1-ca.pugleaf.net!Informatik.Uni-Dortmund.DE!newsReferences:
<sc3f9vb6gk.fsf@lns101.lns.cornell.edu> <1996Jan5.094122.16151@sq.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!Informatik.Uni-Dortmund.DE!news From: schwab@lamothe.informatik.uni-dortmund.de (Andreas Schwab) Newsgroups: comp.std.c Subject: Re: sizeof(1L) in preprocesor;How to tell sizeof(double)>sizeof(long) ? Date: 08 Jan 1996 13:58:51 +0100 Organization: Dortmund University, Germany Sender: schwab@lamothe.informatik.uni-dortmund.de Message-ID: <vyzd98ug7w4.fsf@lamothe.informatik.uni-dortmund.de> References: <sc3f9vb6gk.fsf@lns101.lns.cornell.edu> <1996Jan5.094122.16151@sq.com> Reply-To: schwab@issan.informatik.uni-dortmund.de NNTP-Posting-Host: lamothe.informatik.uni-dortmund.de In-reply-to: msb@sq.com's message of Fri, 5 Jan 1996 09:41:22 GMT X-Newsreader: Gnus v5.0.13