473,811 Members | 3,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which preprocessor is correct?

If you have:
#define errno retrieve_errno_ func()

#define SUBSYSTEM_INCLU DE(subsystem, file) <subsystem/include/file>
then what should happen when you do:
#include SUBSYSTEM_INCLU DE(posix, errno.h)

gcc2.95 pre-processes as intended, to:

#include <posix/include/errno.h>

gcc3.4 preprocessed to:

#include <posix/include/retrueve_errno_ func()>

My guess is that gcc3.4 was the correct one, even though it didn't
produce the intended result.
Jul 24 '08 #1
13 1272
On Jul 24, 4:03 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
If you have:

#define errno retrieve_errno_ func()
unless retrieve_errno_ func is a function-like macro expanding to a
modifiable lvalue, this is wrong.
Jul 24 '08 #2
On Jul 24, 4:18*pm, vipps...@gmail. com wrote:
On Jul 24, 4:03 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:If you have:
* *#define errno retrieve_errno_ func()

unless retrieve_errno_ func is a function-like macro expanding to a
modifiable lvalue, this is wrong.
Why?
Jul 24 '08 #3
fnegroni schrieb:
On Jul 24, 4:18 pm, vipps...@gmail. com wrote:
>On Jul 24, 4:03 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:If you have:
>> #define errno retrieve_errno_ func()
unless retrieve_errno_ func is a function-like macro expanding to a
modifiable lvalue, this is wrong.

Why?
Because errno has to be lvalue-modifyable.

errno = 0;

will not work when errno expands to

foobar() = 0;

Regards,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser können. Es
reicht zu wissen, daß andere es besser können und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
in de.sci.electron ics <47************ ***********@new s.freenet.de>
Jul 24 '08 #4
fnegroni schrieb:
>>Why?
Because errno has to be lvalue-modifyable.

errno = 0;

will not work when errno expands to

foobar() = 0;

And from the incomplete code snippet from the OP, what gave you that
information?
Nothing - but *you* asked why it cannot be a modifyable lvalue.
*retrieve_errno _func_impl() = 2;
Dereferencing any non-const, non-void pointer yields a modifyable
lvalue, which is exactly what I said.

Regards,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser können. Es
reicht zu wissen, daß andere es besser können und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
in de.sci.electron ics <47************ ***********@new s.freenet.de>
Jul 24 '08 #5
On Jul 24, 5:39*pm, Johannes Bauer <dfnsonfsdu...@ gmx.dewrote:
fnegroni schrieb:
On Jul 24, 4:18 pm, vipps...@gmail. com wrote:
On Jul 24, 4:03 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:If you have:
>* *#define errno retrieve_errno_ func()
unless retrieve_errno_ func is a function-like macro expanding to a
modifiable lvalue, this is wrong.
Why?

Because errno has to be lvalue-modifyable.

errno = 0;

will not work when errno expands to

foobar() = 0;
And from the incomplete code snippet from the OP, what gave you that
information?

I can very easily write this complete example, using the OP's code
snippet:

#define retrieve_errno_ func() *retrieve_errno _func_impl()

#define errno retrieve_errno_ func()

int myerrno;

int *retrieve_errno _func_impl()
{
return &myerrno;
}

int
main(void)
{
errno = 2;
return 0;
}

Which will be preprocessed into:

int myerrno;

int *retrieve_errno _func_impl()
{
return &myerrno;
}

int
main(void)
{
*retrieve_errno _func_impl() = 2;
return 0;
}
Jul 24 '08 #6


Please focus on the original topic of which preprocessor was correct.
Jul 24 '08 #7
Tomás Ó hÉilidhe wrote:
If you have:
#define errno retrieve_errno_ func()

#define SUBSYSTEM_INCLU DE(subsystem, file) <subsystem/include/file>
then what should happen when you do:
#include SUBSYSTEM_INCLU DE(posix, errno.h)

gcc2.95 pre-processes as intended, to:

#include <posix/include/errno.h>

gcc3.4 preprocessed to:

#include <posix/include/retrueve_errno_ func()>

My guess is that gcc3.4 was the correct one, even though it didn't
produce the intended result.
What you've shown for gcc3.4 cannot possibly be right, because
an "i" has somehow transmuted to a "u" and a ".h" has vanished.
(I *wish* people would learn to copy-and-paste instead of polluting
their posts with typos ...)

But if the "u" is turned back to "i" and the ".h" is restored,
I believe gcc3.4 is correct (6.10.2p4). Note that

#include < posix / include / retrieve_errno_ func ( ) . h >

would also be correct, because macro replacement works with tokens
(actually "preprocess ing tokens"), not with text. You'll also note
that the way all these pp-tokens get combined into a single header
name is implementation-defined, hence a threat to portability.

--
Er*********@sun .com

Jul 24 '08 #8
Eric Sosman wrote:
Tom�s � h�ilidhe wrote:
If you have:

#define errno retrieve_errno_ func()

#define SUBSYSTEM_INCLU DE(subsystem, file) <subsystem/include/file>

then what should happen when you do:

#include SUBSYSTEM_INCLU DE(posix, errno.h)

gcc2.95 pre-processes as intended, to:

#include <posix/include/errno.h>

gcc3.4 preprocessed to:

#include <posix/include/retrueve_errno_ func()>

My guess is that gcc3.4 was the correct one, even though it didn't
produce the intended result.

What you've shown for gcc3.4 cannot possibly be right, because
an "i" has somehow transmuted to a "u" and a ".h" has vanished.
(I *wish* people would learn to copy-and-paste instead of polluting
their posts with typos ...)

But if the "u" is turned back to "i" and the ".h" is restored,
I believe gcc3.4 is correct (6.10.2p4). Note that

#include < posix / include / retrieve_errno_ func ( ) . h >

would also be correct, because macro replacement works with tokens
(actually "preprocess ing tokens"), not with text.
Which is why the "" form, generated via #, is better IMO. The rules
for
whitespace are much clearer.
You'll also note
that the way all these pp-tokens get combined into a single header
name is implementation-defined, hence a threat to portability.
True, but the #include pp-tokens directive was not exactly designed
with maximal portability in mind! Certainly no more than (say) the
system() function was.

--
Peter
Jul 24 '08 #9
On Jul 24, 11:35 pm, fnegroni <f.e.negr...@go oglemail.comwro te:
On Jul 24, 5:39 pm, Johannes Bauer <dfnsonfsdu...@ gmx.dewrote:
fnegroni schrieb:
On Jul 24, 4:18 pm, vipps...@gmail. com wrote:
>On Jul 24, 4:03 pm, Tomás Ó hÉilidhe <t...@lavabit.c omwrote:If you have:
>> #define errno retrieve_errno_ func()
>unless retrieve_errno_ func is a function-like macro expanding to a
>modifiable lvalue, this is wrong.
Why?
Because errno has to be lvalue-modifyable.
errno = 0;
will not work when errno expands to
foobar() = 0;

And from the incomplete code snippet from the OP, what gave you that
information?

I can very easily write this complete example, using the OP's code
snippet:

#define retrieve_errno_ func() *retrieve_errno _func_impl()
And retrieve_errno_ func() would be a function-like macro expanding to
a modifiable lvalue.
Notice my words:

vippstar said:
>unless retrieve_errno_ func is a function-like macro expanding to a
>modifiable lvalue, this is wrong.
Jul 24 '08 #10

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

Similar topics

25
9144
by: Sabyasachi Basu | last post by:
While trying to port some stuff from Unix to Windows, I encountered a strange behaviour of function macros with empty arguments. Here is a small snippet which illustrates the problem: #include <iostream> #include <string> using namespace std; #define B(X, Y) Y
24
40301
by: Nudge | last post by:
I have an array, and an unrolled loop which looks like this: do_something(A); do_something(A); .... do_something(A); I thought: why should I type so much? I should write a macro. So I was looking to write something along the lines of:
16
4509
by: Trying_Harder | last post by:
Is it possible to redefine a macro with global scope after undefining it in a function? If yes, could someone explain how? /If/ my question above isn't very clear you can refer to the following example. eg cosider 2 files sample.c and sample.h sample.h
13
2141
by: Chris Croughton | last post by:
Is the following code standard-compliant, and if so what should it do? And where in the standard defines the behaviour? #include <stdio.h> #define DEF defined XXX int main(void) { int defined = 2;
32
2808
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input the same file ? If not then how much variation is allowed ? Is it just a bit more or less white space here and there or could could there be larger differences ? If the output is not deterministic then is it possible that the output of the...
6
3135
by: olivier.grant | last post by:
Hi All, I'm trying to define a macro that will allow me to write the following code : #include MY_MACRO( NAME, SPACE ) and end up with the following preprocessed code : #include NAME.hpp
6
2282
by: 2112 | last post by:
I'm compiling a dll that imports msado15.dll. When I'm using Windows in English, the msado15.dll is located at <drive>:\Program Files\Common Files\System\ADO\msado15.dll". When using Windows in Portuguese, the msado15.dll is located at <drive>:\Arquivos de programas\Arquivos comuns\System\ADO\msado15.dll I'd know if exists some preprocessor directive that could identify the language of Windows and import msado15.dll from the correct...
31
2945
by: Sam of California | last post by:
Is it accurate to say that "the preprocessor is just a pass in the parsing of the source file"? I responded to that comment by saying that the preprocessor is not just a pass. It processes statements that the compiler does not process. The good people in the alt.comp.lang.learn.c-c++ newsgroup insist that the preprocessor is just one of many passes. The preprocessor processes a grammer unique to the preprocessor and only that grammer. ...
14
12463
by: dan | last post by:
I would like to have the preprocessor automatically generate the number of array elements requested. Each element is zero. The elements get pasted into a larger array. The other elements may be non-zero. ***** Here is an example of what I need to do: #define YEAR_1 2005 #define YEAR_2 2007 #define YEARS (YEAR_2 - YEAR_1 + 1)
0
9605
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
10393
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10405
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
9208
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
7671
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
6893
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
5556
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...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.