==C90:
Errata for K&R2 page 232 (from http://www-db-out.research.bell-labs...ediffs.html):\
232(§A12.5): The result of the defined operator is not replaced
literally by 0L or 1L, nor are undefined names literally by 0L, but just
by plain 0 or 1. However, the constant expression is nevertheless
evaluated as if these and *other constants* appearing have long or
unsigned long type.
When it mentions "these and other constants", what are the other
constants implied? 5 1760
Ioannis Vranos wrote:
Errata for K&R2 page 232 (from http://www-db-out.research.bell-labs...ediffs.html):\
232(§A12.5): The result of the defined operator is not replaced
literally by 0L or 1L, nor are undefined names literally by 0L, but just
by plain 0 or 1. However, the constant expression is nevertheless
evaluated as if these and *other constants* appearing have long or
unsigned long type.
When it mentions "these and other constants", what are the other
constants implied?
That would certainly include the user literals, such as 2 in
#if X 2
--
Thad
Thad Smith wrote:
Ioannis Vranos wrote:
>Errata for K&R2 page 232 (from http://www-db-out.research.bell-labs...ediffs.html):\
232(§A12.5): The result of the defined operator is not replaced literally by 0L or 1L, nor are undefined names literally by 0L, but just by plain 0 or 1. However, the constant expression is nevertheless evaluated as if these and *other constants* appearing have long or unsigned long type.
When it mentions "these and other constants", what are the other constants implied?
That would certainly include the user literals, such as 2 in
#if X 2
So when
#define SOMETHING 6
is used, the 6 is considered as long or unsigned long?
Also I can't understand the following sentence completely:
"However, the constant expression"
I suppose it means the expression
defined identifier
or
defined ( identifier)
"is nevertheless evaluated as if these and other constants"
Which constants does it mean with "these", and which constants does it
mean with "other"?
"appearing have long or unsigned long type".
In article <ft***********@ulysses.noc.ntua.gr>,
Ioannis Vranos <iv*****@nospam.no.spamfreemail.grwrote:
>Also I can't understand the following sentence completely:
>"However, the constant expression"
>I suppose it means the expression
>defined identifier
>or
>defined ( identifier)
Yes.
>"is nevertheless evaluated as if these and other constants"
>Which constants does it mean with "these",
The 0 or 1 that results from evaluating the 'defined' operator.
>and which constants does it mean with "other"?
User literal numbers, macros that expand to user literal numbers.
>"appearing have long or unsigned long type".
If a literal constant without a suffix is greater than LONG_MAX then it
will be treated as unsigned. I believe everything else follows from the
usual promotion rules for mixing signed and unsigned values -- so if you
add two large unsuffixed numeric literals each less than LONG_MAX,
that would be a signed operation, with overflow a possibility
I believe (it is a constraint violation to evaluate to something
that is outside the representable range for the type, due to
the #if processing of constant expressions to be done the same way
as for constant expressions in normal text, and the appropriate
section of the standard for that has a "shall" clause requiring
keeping within the representable range.)
--
This is a Usenet signature block. Please do not quote it when replying
to one of my postings. http://en.wikipedia.org/wiki/Signature_block
Walter Roberson wrote:
In article <ft***********@ulysses.noc.ntua.gr>,
Ioannis Vranos <iv*****@nospam.no.spamfreemail.grwrote:
>Also I can't understand the following sentence completely:
>"However, the constant expression"
>I suppose it means the expression
>defined identifier
>or
>defined ( identifier)
Yes.
>"is nevertheless evaluated as if these and other constants"
>Which constants does it mean with "these",
The 0 or 1 that results from evaluating the 'defined' operator.
>and which constants does it mean with "other"?
User literal numbers, macros that expand to user literal numbers.
>"appearing have long or unsigned long type".
If a literal constant without a suffix is greater than LONG_MAX then it
will be treated as unsigned. I believe everything else follows from the
usual promotion rules for mixing signed and unsigned values -- so if you
add two large unsuffixed numeric literals each less than LONG_MAX,
that would be a signed operation, with overflow a possibility
I believe (it is a constraint violation to evaluate to something
that is outside the representable range for the type, due to
the #if processing of constant expressions to be done the same way
as for constant expressions in normal text, and the appropriate
section of the standard for that has a "shall" clause requiring
keeping within the representable range.)
I didn't understand the above. User literal integer numbers without a
suffix are considered as ints.
The text mentions that "However, the constant expression is nevertheless
evaluated as if these and other constants appearing have long or
unsigned long type", not int or unsigned int.
I suppose it means that when we have:
#define WHATEVER 123
#if defined (WHATEVER)
in defined statement, the WHATEVER is considered as long or unsigned
long, but I am not sure if this is what it means.
Ioannis Vranos writes:
So when
#define SOMETHING 6
is used, the 6 is considered as long or unsigned long?
In preprocessor arithmetic in C89, yes. 6 is considered long since it
fits in a long. 4000000000 does not fit in a long but fits in an
unsigned long if long is 32-bit, so it is treated as unsigned long.
The idea is that preprocessor arithmetic is done in the largest standard
integer type available. So C89 compilers use long or unsigned long,
while C99 compilers use intmax_t or uintmax_t (which is at least as wide
as long long).
C89 compilers which support long long as an extension (except I'm not
sure that's strictly speaking a C89 compiler) can complicate this -
obviously "long long" constants should not be truncated to "long".
The most natural solution would be the usual arithmetic conversions -
e.g. ULONG_MAX + 1 == 0L but ULONG_MAX + 1LL promotes ULONG_MAX to
long long so the result is 0x100000000LL or whatever.
--
Hallvard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jim Cook |
last post by:
We have a macro which takes various index constants as an argument and
offsets into an array. The macro can be an Lvalue or Rvalue. The index
is not zero based. I would like a compile time error displayed if the
index is out of bounds. Is there a way to do this well?
I read through the FAQ that I could find mentioned, and did not see this...
|
by: Simon Morgan |
last post by:
Hi,
Can somebody please help me grok the offsetof() macro?
I've found an explanation on
http://www.embedded.com/shared/printableArticle.jhtml?articleID=18312031
but I'm afraid it still doesn't make sense to me.
The sticking point seems to be:
|
by: ethan |
last post by:
Hi All,
How to write a macro with variable length of argument?
For example, if i need a macro to check return value of printf.
#define PRINTF_ESC(x, ...) if(printf(x, ...) == 10) goto end;
However, it doesn't work. >_<
Thank you very much.
|
by: rachelm81 |
last post by:
Hello, all! I'm creating a macro for help with some c/c++ projects, and within it, I'm trying to execute Find/Replace. Actually, it's executing fine. It's closing the prompt that I'm having a problem with. Here's a snipet of the code:
DTE.ItemOperations.OpenFile(path + sFile)
ActiveDocument.Selection.StartOfDocument()...
|
by: Benne Smith |
last post by:
I can't seem to use my normal compiler constants from inside a macro ?
It's possible to define NEW constants inside the macro, but this is not what
i need.
Does anybody know a way to get to them from inside the macro ?
Thanks,
Benne
| |
by: sounak |
last post by:
How could we get a macro name from a macro value
such that
in a header file
#define a 100
#define b 200
now the source file will be such that
the user gives 100
then the value is outputted as a
the user gives 200
then the value is outputted as b
|
by: Richard Meister |
last post by:
Hi,
I'd like to define several constants and make sure that all of them are
smaller than a given other constant. I thought this could be done by a
simple macro. Something like this:
#define MAX 999
#define DEF_CHECKED_VAL( name, value) #if (value < MAX) \
#define name MAX \
|
by: jason |
last post by:
Hi,
I learned my lesson about passing pointers, but now I have a question
about macros.
Why does the function work and the MACRO which is doing the same thing
on the surface, does not work in the following small example ?
#include <stdio.h>
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
Here's a macro that Mathew Hendry posted back in the year 2000 for
achieving binary integer literals that evaluate to compile-time
constants:
#define BIN8(n)\
(((0x##n##ul&1<< 0)>0)|((0x##n##ul&1<< 4)>3)\
|((0x##n##ul&1<< 8)>6)|((0x##n##ul&1<<12)>9)\
|((0x##n##ul&1<<16)>>12)|((0x##n##ul&1<<20)>>15)\...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |