473,804 Members | 3,178 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 2526
In article <8e************ *******@news.in digo.ie>,
Frederick Gotham <fg*******@SPAM .comwrote:
>I'd like to ask any other programmers to explain to me why:

sizeof (unsigned long)(60UL * 60UL * 24UL * 365UL)

would have been undesireable.
Because it's a syntax error.
>The expression in question has only one possible parse, because the operand
of "sizeof" cannot be a cast expression.
It has no possible parses.
>Therefore, the following two
expressions are exactly equivalent:

sizeof (unsigned long)(60UL * 60UL * 24UL * 365UL)

sizeof ((unsigned long)(60UL * 60UL * 24UL * 365UL))
No, one of them's an error and the other one isn't.

-- Richard
Oct 24 '06 #21
Richard Tobin posted:
> sizeof (unsigned long)(60UL * 60UL * 24UL * 365UL)

Because it's a syntax error.

So you can turn a cast expression into a normal expression (or whatever it's
called) by enclosing it in parentheses?

--

Frederick Gotham
Oct 24 '06 #22
In article <JJ************ *******@news.in digo.ie>,
Frederick Gotham <fg*******@SPAM .comwrote:
>So you can turn a cast expression into a normal expression (or whatever it's
called) by enclosing it in parentheses?
Yes, it becomes a primary expression (IIRC - I don't have the grammar
handy). That's the basic way of making the grammar handle arbitrarily
complicated expressions: by putting a subexpression in parentheses it
becomes usable in the same contexts as numbers and strings.

-- Richard
Oct 24 '06 #23
Frederick Gotham wrote:
Richard Tobin posted:
>> sizeof (unsigned long)(60UL * 60UL * 24UL * 365UL)

Because it's a syntax error.

So you can turn a cast expression into a normal expression (or whatever it's
called) by enclosing it in parentheses?
Looking at the grammar ...

The operand of a `sizeof` must be a unary-expression. A unary-expression
can be a postfix-expression, which can be a primary-expression, which can
be any expression enclosed in parentheses.

So yes, parenthesising a cast-expression makes it suitable as an
operand of `sizeof`.

I wouldn't have thought this was surprising: putting bracketty things
around big wobbly expresssions to make them into snug tight expressions
is a common grammatical trick, eg `2 * (20 + 1)`.

--
Chris "common, but not universal" Dollin
A rock is not a fact. A rock is a rock.

Oct 24 '06 #24
Frederick Gotham wrote:
Richard Tobin posted:
>> sizeof (unsigned long)(60UL * 60UL * 24UL * 365UL)
Because it's a syntax error.


So you can turn a cast expression into a normal expression (or whatever it's
called) by enclosing it in parentheses?
Of course you can it's spelled out pretty clearly in the grammar. Any
'expression' enclosed in parentheses is a 'primary-expression':

(6.5.1)primary-expression:
identifier
constant
string-literal
( expression )

And a 'cast-expression' is a 'multiplicative-expression'
which is, in turn an 'additive-expression'
which is, in turn a 'shift-expression'
which is, in turn a 'relational-expression'
which is, in turn an 'equality-expression'
which is, in turn an 'AND-expression'
which is, in turn a 'exclusive-OR-expression'
which is, in turn a 'inclusive-OR-expression'
which is, in turn a 'logical-AND-expression'
which is, in turn a 'logical-OR-expression'

which is, in turn a 'conditional-expression'
which is, in turn a 'assignment-expression'
which is, in turn an 'expression'

*pant* *pant* *pant*
--
Clark S. Cox III
cl*******@gmail .com
Oct 24 '06 #25
On Tue, 24 Oct 2006 15:23:48 GMT, in comp.lang.c , Frederick Gotham
<fg*******@SPAM .comwrote:
>Since the two self-proclaimed masters of this newsgroup won't reply to me,
Lets all recall that the reason these (and other) regulars don't reply
is because you're offensive. Nobody can be bothered.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 24 '06 #26
Frederick Gotham wrote:
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'd like to ask any other programmers to explain to me why:
Well, I haven't gone quite that far, but the fact is that you know
very well how to repair that situation. You have chosen not to do
so for your own incomprehensibl e reasons, and continue to insult
them. I suspect many others are ignoring you without advising you
of the fact.

Enjoy Coventry.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net>
Oct 24 '06 #27
Richard Heathfield <in*****@invali d.invalidwrites :
Keith Thompson said:
>Frederick Gotham <fg*******@SPAM .comwrites:
>>Keith Thompson posted:
You want parentheses around the second defintion:

#define SECONDS_PER_YEA R ((unsigned long)(60UL * 60UL * 24UL * 365UL)(

Consider "sizeof SECONDS_PER_YEA R".

I don't understand... what could that have parsed to?

Frederick, I don't want to leave you waiting for a response from me,
so I'll remind you of this:

<http://groups.google.c om/group/comp.lang.c/msg/a03c532b26664ed 4>

A waste of time, Keith. If he were interested in responses from you, he'd
have apologised a long time ago.
I'm not waiting for, or expecting, an apology from him. See the
article I cited if you care (but there's no real reason you should).
I wasn't trying to elicit any particular response from him, just
reminding him that he shouldn't expect one from me.

--
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.
Oct 24 '06 #28
Keith Thompson <ks***@mib.orgw rote:
You want parentheses around the second defintion:
^^^^^^^^^
#define SECONDS_PER_YEA R ((unsigned long)(60UL * 60UL * 24UL * 365UL)(
Did you mean

#defin SECONDS_PER_YEA R ((unsigned long)(60UL * 60UL * 24UL * 365UL))

or was that a typo too? :-)

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gma il.com | don't, I need to know. Flames welcome.
Oct 24 '06 #29
Christopher Benson-Manica <at***@otaku.fr eeshell.orgwrit es:
Keith Thompson <ks***@mib.orgw rote:
>You want parentheses around the second defintion:
^^^^^^^^^
>#define SECONDS_PER_YEA R ((unsigned long)(60UL * 60UL * 24UL * 365UL)(

Did you mean

#defin SECONDS_PER_YEA R ((unsigned long)(60UL * 60UL * 24UL * 365UL))

or was that a typo too? :-)
Yes, taht wsa a tpyo. :)-

--
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.
Oct 24 '06 #30

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
9584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10583
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
9160
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
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.