473,379 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

#define constants

I think I read somewhere that #define constants in the style
#define SOMETHING 6
are evaluated to long or unsigned long, depending on the situation and
not int.
Apr 3 '08 #1
7 2014
Ioannis Vranos wrote:
I think I read somewhere that #define constants in the style
#define SOMETHING 6
are evaluated to long or unsigned long, depending on the situation and
not int.

.... Is that true?
Apr 3 '08 #2
Ioannis Vranos wrote:
Ioannis Vranos wrote:
>I think I read somewhere that #define constants in the style
#define SOMETHING 6
are evaluated to long or unsigned long, depending on the situation
and not int.


... Is that true?
I don't know whether it's true that you read that nonsense somewhere
or whether you dreamed it. I know that an integral literal has the
type 'int' if it fits in it, and if it doesn't, it has type long int,
unless overridden by a suffix (absent in your example). This all is
defined in [lex.icon]/2.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 3 '08 #3
Victor Bazarov wrote:
Ioannis Vranos wrote:
>Ioannis Vranos wrote:
>>I think I read somewhere that #define constants in the style
#define SOMETHING 6
are evaluated to long or unsigned long, depending on the situation
and not int.

... Is that true?

I don't know whether it's true that you read that nonsense somewhere
or whether you dreamed it. I know that an integral literal has the
type 'int' if it fits in it, and if it doesn't, it has type long int,
unless overridden by a suffix (absent in your example). This all is
defined in [lex.icon]/2.

My mistake. It is about the "identifier" of the macro expressions

defined identifier

and

defined ( identifier)
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.
Apr 3 '08 #4
Ioannis Vranos wrote:
Victor Bazarov wrote:
>Ioannis Vranos wrote:
>>Ioannis Vranos wrote:
I think I read somewhere that #define constants in the style
#define SOMETHING 6
are evaluated to long or unsigned long, depending on the situation
and not int.
... Is that true?
I don't know whether it's true that you read that nonsense somewhere
or whether you dreamed it. I know that an integral literal has the
type 'int' if it fits in it, and if it doesn't, it has type long int,
unless overridden by a suffix (absent in your example). This all is
defined in [lex.icon]/2.


My mistake. It is about the "identifier" of the macro expressions

defined identifier

and

defined ( identifier)
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.

The fact that the "identifier" in a "defined" preprocessor statement is
evaluated as long or unsigned long, doesn't it imply that this
identifier which was defined with #define" preprocessor statement is
evaluated as long or unsigned long everywhere?
Apr 3 '08 #5
Ioannis Vranos wrote:
Ioannis Vranos wrote:
>Victor Bazarov wrote:
>>Ioannis Vranos wrote:
Ioannis Vranos wrote:
I think I read somewhere that #define constants in the style
>
>
#define SOMETHING 6
>
>
are evaluated to long or unsigned long, depending on the situation
and not int.
... Is that true?
I don't know whether it's true that you read that nonsense somewhere
or whether you dreamed it. I know that an integral literal has the
type 'int' if it fits in it, and if it doesn't, it has type long int,
unless overridden by a suffix (absent in your example). This all is
defined in [lex.icon]/2.

My mistake. It is about the "identifier" of the macro expressions

defined identifier

and

defined ( identifier)
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.


The fact that the "identifier" in a "defined" preprocessor statement is
evaluated as long or unsigned long, doesn't it imply that this
identifier which was defined with #define" preprocessor statement is
evaluated as long or unsigned long everywhere?

My mistake again, the _result_ of the defined operator is replaced by 0
or 1 which are evaluated as 0L and 1L. Strange stuff.
Apr 3 '08 #6
OK, lets get it from the start again:
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?
Apr 3 '08 #7
Ioannis Vranos wrote:
I think I read somewhere that #define constants in the style
#define SOMETHING 6
are evaluated to long or unsigned long, depending on the situation and
not int.
Nope. Not true. #define has little to do with (unless you are
throwing in some token pasting operators), an decimal integer literal
has type the smaller of int or long int that can hold it.

Other constraints on the language make 6 HAVE to be of type int.

There's no way a decimal literal ever has type unsigned.
Apr 3 '08 #8

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

Similar topics

8
by: John Ratliff | last post by:
Let's say I had a program which uses some constants. Would it be "better" to declare them like this: #ifndef __MY_HDR_FILE #define __MY_HDR_FILE #define STRING_CONST "some string..." #define...
97
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
7
by: Morgan Cheng | last post by:
Hi, In my program module, there are some Constants should be defined to be integer key value of std::map. In the module, methods of a few classes will return std::map containing value indexed by...
2
by: Andreas | last post by:
Hi! I'm using an IplImage library from camellia.sourceforge.net, and the testbench calls a file only containing code like the one below. In cam_morphomaths_code.c the real computation is made,...
7
by: Peng Yu | last post by:
I'm not very clear about when to use #define and when to use const? #define number 4 const int number = 4; If I just want to define a global constant, which way of the above is better? ...
4
by: Amadelle | last post by:
Hi all and thanks again in advance, What is the best way of defining global constants in a C# application? (A windows application with no windows forms - basically a set of classes). Would it be...
7
by: Don Wash | last post by:
Hi There! I'm trying to define constants so that I can refer those constants from any page of my ASP.NET website. I know I can use <appSettings> in web.config XML file but I don't want to parse...
27
by: pereges | last post by:
I need to define the plancks constant 6.67 X 10 exp -34. Is it possible to do it using #define or would you suggest using a (static ?)const double.
7
by: Chris Saunders | last post by:
I'm not very familiar with C#. I have a static class and would like to define some constants similarily to Math.PI. Could someone show me how to go about doing this. So far no luck searching. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.