If you have:
#define errno retrieve_errno_func()
#define SUBSYSTEM_INCLUDE(subsystem, file) <subsystem/include/file>
then what should happen when you do:
#include SUBSYSTEM_INCLUDE(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. 13 1237
On Jul 24, 4:03 pm, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
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.
On Jul 24, 4:18*pm, vipps...@gmail.com wrote:
On Jul 24, 4:03 pm, Tomás Ó hÉilidhe <t...@lavabit.comwrote: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?
fnegroni schrieb:
On Jul 24, 4:18 pm, vipps...@gmail.com wrote:
>On Jul 24, 4:03 pm, Tomás Ó hÉilidhe <t...@lavabit.comwrote: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.electronics <47***********************@news.freenet.de>
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.electronics <47***********************@news.freenet.de>
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.comwrote: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;
}
Please focus on the original topic of which preprocessor was correct.
Tomás Ó hÉilidhe wrote:
If you have:
#define errno retrieve_errno_func()
#define SUBSYSTEM_INCLUDE(subsystem, file) <subsystem/include/file>
then what should happen when you do:
#include SUBSYSTEM_INCLUDE(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 "preprocessing 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
Eric Sosman wrote:
Tom�s � h�ilidhe wrote:
If you have:
#define errno retrieve_errno_func()
#define SUBSYSTEM_INCLUDE(subsystem, file) <subsystem/include/file>
then what should happen when you do:
#include SUBSYSTEM_INCLUDE(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 "preprocessing 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
On Jul 24, 11:35 pm, fnegroni <f.e.negr...@googlemail.comwrote:
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.comwrote: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.
On 25 Jul, 01:03, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
If you have:
#define errno retrieve_errno_func()
This causes undefined behaviour if errno.h
is included, BTW.
Tomás Ó hÉilidhe schrieb:
Please focus on the original topic of which preprocessor was correct.
Why should we? Although the topic has changed, the discourse is still
topical in c.l.c. - therefore I see no reason why one should not
digress. Most *really* interesting discussions evolve from something
which was not the primary question.
So unless I get paid for writing in c.l.c. I feel free to comment on
whatever appears to interest me :-)
Kind 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.electronics <47***********************@news.freenet.de>
Eric Sosman wrote:
Tomás Ó hÉilidhe wrote:
>If you have:
#define errno retrieve_errno_func()
#define SUBSYSTEM_INCLUDE(subsystem, file) <subsystem/include/file>
then what should happen when you do:
#include SUBSYSTEM_INCLUDE(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 "preprocessing 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.
I don't agree. From section 6.4 and 6.4.7, the header-name is a
indivisible token, so it should not be splitt and substituted.
ciao
cate
Giacomo Catenazzi wrote:
Eric Sosman wrote:
>Tomás Ó hÉilidhe wrote:
>>If you have:
#define errno retrieve_errno_func()
#define SUBSYSTEM_INCLUDE(subsystem, file) <subsystem/include/file>
then what should happen when you do:
#include SUBSYSTEM_INCLUDE(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 "preprocessing 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.
I don't agree. From section 6.4 and 6.4.7, the header-name is a
indivisible token, so it should not be splitt and substituted.
The line
#include SUBSYSTEM_INCLUDE(posix, errno.h)
does not contain a header-name token. A header-name has one of
the two forms
< h-char-sequence >
or
" q-char-sequence "
.... and the given line matches neither of these. So neither of
6.10.2p2 nor 6.10.2p3 applies, and we must turn to 6.10.2p4 to
describe how the line is processed. There we find that the
line is read as
# include pp-tokens new-line
.... and that the list of pp-tokens is subject to macro replacement.
After replacement, the pp-tokens are reassembled into one of the two
header-name forms in an implementation-defined way.
-- Er*********@sun.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
| |