473,804 Members | 3,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what's wrong with the macro


#include<stdio. h>
#include<stdlib .h>
#include<string .h>

#define SECONDS_PER_YEA R (60*60*24*365)U L
int main()
{
unsigned long int u_i = SECONDS_PER_YEA R;
printf("%lu\n", u_i);

return 0;
}
cc -g -c -Wall -std=c99 -DDEBUG define.c
define.c: In function 'main':
define.c:17: error: expected ',' or ';' before 'UL'
make: *** [define.o] error 1

Oct 22 '06
38 2528
Keith Thompson wrote:
>
ro******@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
In article <45***********@ mindspring.com> ,
pete <pf*****@mindsp ring.comwrote:
>"Giorgio Silvestri" <gi************ **@libero.itwri tes:
#define SECONDS_PER_YEA R ((unsigned long)(60UL * 60UL * 24UL * 365UL))
>What is the cast for?

I believe it's superfluous.
Once the constant (without the cast) is computed by the parser, it
becomes a numeric value of indeterminate width -- through some unspecified
mechanism the parser knows the minimum width needed to represent it,
but it is not specifically that minimum width and not specifically UL
and so on. If the cast-less constant were determined
to be too large to match the other operand of the expression, then
widening is going to take place. In some contexts, if the constant
were determined to be able to fit within the *signed* version of
a larger type, it would be widened to *signed* rather than to
unsigned [remember, the system knows it as a numeric value at that point,
not specifically as an unsigned numeric value.]. The (unsigned long) cast
stops any uncertainty about exactly what type is going to be there.

I don't think so. C99 6.6p11 says:

The semantic rules for the evaluation of a constant expression are
the same as for nonconstant expressions.

The expression:

(60UL * 60UL * 24UL * 365UL)

is a constant expression, but not a constant (i.e., a literal).

A single integer literal with a UL suffix is of type unsigned long int
or unsigned long long int, depending on the value; all the constants
in the above are well within the guaranteed range of unsigned long, so
that's their type. Multiplying an unsigned long by an unsigned long
yields an unsigned long, so the entire expression is of type unsigned
long.

As it happens, the final result, 31536000, is also within the
guaranteed range of unsigned long, so there's no possibility of
overflow. But even if there were (say, if you wanted the number of
seconds in a millenium), an overflow wouldn't change the type of the
expression.
(60UL * 60 * 24 * 365) would be OK
even if (60 * 24 * 365) was greater than INT_MAX.

--
pete
Oct 24 '06 #31

"Frederick Gotham" <fg*******@SPAM .comwrote in message
news:8e******** ***********@new s.indigo.ie...
Keith Thompson posted:

<snip tripe>

Richard Heathfield posted:

<snip tripe>

Since the two self-proclaimed masters of this newsgroup won't reply to me,
I'm also a self-proclaimed master of this newsgroup and I'm replying to you
here. There is still hope

Jan 2 '07 #32
Serve Laurijssen wrote:
"Frederick Gotham" <fg*******@SPAM .comwrote in message
news:8e******** ***********@new s.indigo.ie...
>Keith Thompson posted:

<snip tripe>

Richard Heathfield posted:

<snip tripe>

Since the two self-proclaimed masters of this newsgroup won't reply to me,

I'm also a self-proclaimed master of this newsgroup and I'm replying to you
here. There is still hope
"I'm in charge, here."
Jan 2 '07 #33
"Serve Laurijssen" <se*@n.tkwrites :
"Frederick Gotham" <fg*******@SPAM .comwrote in message
news:8e******** ***********@new s.indigo.ie...
>Keith Thompson posted:

<snip tripe>

Richard Heathfield posted:

<snip tripe>

Since the two self-proclaimed masters of this newsgroup won't reply to me,

I'm also a self-proclaimed master of this newsgroup and I'm replying to you
here. There is still hope
You're a bit late. The article to which you're replying was posted on
October 24. Frederick Gotham apologized handsomely for his earlier
behavior on November 11, and has been quite untrollish since then
(though he hasn't posted here in about a month).

--
Keith Thompson (The_Other_Keit h) 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.
Jan 2 '07 #34
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.orgw rote:
>"Serve Laurijssen" <se*@n.tkwrites :
>"Frederick Gotham" <fg*******@SPAM .comwrote in message
news:8e******* ************@ne ws.indigo.ie...
>>Keith Thompson posted:

<snip tripe>

Richard Heathfield posted:

<snip tripe>

Since the two self-proclaimed masters of this newsgroup won't reply to me,

I'm also a self-proclaimed master of this newsgroup and I'm replying to you
here. There is still hope

You're a bit late. The article to which you're replying was posted on
October 24. Frederick Gotham apologized handsomely for his earlier
behavior on November 11, and has been quite untrollish since then
(though he hasn't posted here in about a month).
I think it was pretty well established at the time that those "apologies"
were forged by the "regulars".

Jan 2 '07 #35
Keith Thompson <ks***@mib.orgw rites:
[...]
You're a bit late. The article to which you're replying was posted on
October 24. Frederick Gotham apologized handsomely for his earlier
behavior on November 11, and has been quite untrollish since then
(though he hasn't posted here in about a month).
And there's been zero evidence that his apology was anything other
than genuine (if it were forged, Frederick would have had ample
opportunity to say so).

--
Keith Thompson (The_Other_Keit h) 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.
Jan 3 '07 #36
Kenny McCormack said:
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.orgw rote:
<snip>
>>You're a bit late. The article to which you're replying was posted on
October 24. Frederick Gotham apologized handsomely for his earlier
behavior on November 11, and has been quite untrollish since then
(though he hasn't posted here in about a month).

I think it was pretty well established at the time that those "apologies"
were forged by the "regulars".
Mr McCormack is incorrect, as usual.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 3 '07 #37
Clever Monkey wrote:
Serve Laurijssen wrote:
>"Frederick Gotham" <fg*******@SPAM .comwrote in message
.... snip ...
>>>
Since the two self-proclaimed masters of this newsgroup won't
reply to me,

I'm also a self-proclaimed master of this newsgroup and I'm
replying to you here. There is still hope

"I'm in charge, here."
"I'm the commander--see, I don't have to explain -- I don't need
to explain why I say things. That's the interesting thing about
being the President. Maybe somebody needs to explain to me why
they say something, but I don't feel like I owe anybody an
explanation." - George W. Bush, 2002-11-19

"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - GWB 2004-2-8

"If I knew then what I know today, I would still have invaded
Iraq. It was the right decision" - G.W. Bush, 2004-08-02

"This notion that the United States is getting ready to attack
Iran is simply ridiculous. And having said that, all options
are on the table." - George W. Bush, Brussels, 2005-02-22

Who's in charge?

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Jan 3 '07 #38
CBFalconer <cb********@yah oo.comwrote:
Clever Monkey wrote:
Serve Laurijssen wrote:
"Frederick Gotham" <fg*******@SPAM .comwrote in message
... snip ...
>>
Since the two self-proclaimed masters of this newsgroup won't
reply to me,

I'm also a self-proclaimed master of this newsgroup and I'm
replying to you here. There is still hope
"I'm in charge, here."

"I'm the commander--see, I don't have to explain -- I don't need
to explain why I say things. That's the interesting thing about
being the President. Maybe somebody needs to explain to me why
they say something, but I don't feel like I owe anybody an
explanation." - George W. Bush, 2002-11-19

"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - GWB 2004-2-8

"If I knew then what I know today, I would still have invaded
Iraq. It was the right decision" - G.W. Bush, 2004-08-02

"This notion that the United States is getting ready to attack
Iran is simply ridiculous. And having said that, all options
are on the table." - George W. Bush, Brussels, 2005-02-22

Who's in charge?
Cheney.

Richard
Jan 3 '07 #39

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

Similar topics

220
19190
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
4
6270
by: Martin Magnusson | last post by:
I'm using a matrix and vector library, that won't compile. When running g++ I get the error message "macro "minor" passed 5 arguments, but takes just 1" The definition of "minor" looks like below, and it takes 3 arguments. All calls to minor that I have found in the code also pass it three arguments, so I really don't understand this error. Does anything look suspicious with the following definition, or must it be that there is some...
8
3554
by: sandwich_eater | last post by:
I get compiler error "cerr undeclared first use this function." #define err_ret(e) cerr << e; return -1 .... err_ret("who ate my muffy?");
7
23560
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead. Execution is faster. Where will it be stotred?(Is it in bss/stack/?) FUNCTION:
4
3224
by: Louly | last post by:
Hi everybody, I got the code for dimming a menu item from this group after looking for it for a long time thanks to those who share their experiences with the others :) The problem I'm facing is that it dims the wrong menu item!! Example, if I write "DoCmd.SetMenuItem 0, 2, , acMenuGray", it dims the 3rd command in the 2nd menu!! It's driving me crazy!
14
2451
by: raghu | last post by:
Hello I have a doubt plz clarify that #ifndef SYSTEM_H #define SYSTEM_H what will be the value of SYATEM_H after this #define statement and before that statement. Thanking you all Bye
4
2136
by: Gestorm | last post by:
Hi all, I found a macro "USE_VAR" in the code of bash-3.2 as follows: /*file: bash-3.2/shell.c*/ 344 USE_VAR(argc); 345 USE_VAR(argv); 346 USE_VAR(env); 347 USE_VAR(code); 348 USE_VAR(old_errexit_flag); 349 #if defined (RESTRICTED_SHELL) 350 USE_VAR(saverst);
31
2452
by: Tommy | last post by:
struct stat *stats IF_LINT (= 0); I don't know why "IF_LINT (= 0)" is needed ? Source is df.c of df program on Linux coreutils-5.2.1\coreutils-5.2.1\src Thanks!
32
2747
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template issue. A noddy mixin layer example should illustrate the issue... class Base { protected: int m_Field;
0
9707
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10586
Oralloy
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10323
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7622
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6856
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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
3
2997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.