This code snippet below does compiles,
#include<sys/types.h>
#include<sys/wait.h>
#include<iostream>
int main()
{
int ret = 0xFFFF;
std::cout << WEXITSTATUS(ret);
}
whereas this code snippet does not compile indeed with G++ 4.9.4
:
#include<sys/types.h>
#include<sys/wait.h>
#include<iostream>
int main()
{
std::cout << WEXITSTATUS(0xFFFF);
}
Here is what the compiler complains:
In file included from /usr/include/x86_64-linux-gnu/sys/wait.h:77:0,
from t.cpp:2:
t.cpp: In function ‘int main()’:
t.cpp:7:22: error: lvalue required as unary ‘&’ operand
std::cout << WEXITSTATUS(0xFFFF);
^
Here is the detail info about the compiler:
g++ --version
g++ (Ubuntu 4.9.4-2ubuntu1~16.04) 4.9.4
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
And the compiler is installed on Ubuntu16.04 by the commands below
sudo apt-get install gcc-4.9
sudo apt-get install g++-4.9
sudo update-alterntives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alterntives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
Note: I have to use g++-4.9, I have no other choice.
And It's strange that I could not reproduce the said phenomenon on godbolt.org
. It compiles on godbolt.org with gcc 4.9.3
(gcc 4.9.4
is not available).
Here is the output of g++ -E the_said_code_snippet_does_not_compile.cpp
//omit
# 4 "t.cpp" 2
int main()
{
std::cout << ((((*(const int *) &(0xFFFF))) & 0xff00) >> 8);
}
Could anybody shed some light on this matter?
UPDATED:
I can reproduce the error now!See this link.
UPDATED:
It's just a simplified example. What am I actually face is WEXITSTATUS(pclose(fp))
does not compile.