Bug 71914 - Name 'DOMAIN' is blocked when including math.h
Summary: Name 'DOMAIN' is blocked when including math.h
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.8.5
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-18 06:52 UTC by henad221
Modified: 2016-07-18 08:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description henad221 2016-07-18 06:52:19 UTC
#include <math.h>
#include <stdio.h>

int DOMAIN = 3;

int main() {
  printf("%d\n", DOMAIN);
  return 0;
}

Compiled with:

gcc -v domain.cpp

Produces:

gcc -v domain.cpp 
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.8/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.5-2ubuntu1~14.04.1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-i386 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-targets=all --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.8.5 (Ubuntu 4.8.5-2ubuntu1~14.04.1) 
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=i686'
 /usr/lib/gcc/i686-linux-gnu/4.8/cc1plus -quiet -v -imultiarch i386-linux-gnu -D_GNU_SOURCE domain.cpp -quiet -dumpbase domain.cpp -mtune=generic -march=i686 -auxbase domain -version -fstack-protector -Wformat -Wformat-security -o /tmp/ccDxzNcb.s
GNU C++ (Ubuntu 4.8.5-2ubuntu1~14.04.1) version 4.8.5 (i686-linux-gnu)
	compiled by GNU C version 4.8.5, GMP version 5.1.3, MPFR version 3.1.3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/i386-linux-gnu/c++/4.8"
ignoring nonexistent directory "/usr/local/include/i386-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/i686-linux-gnu/4.8/../../../../i686-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/dyknowaccount/ros_catkin_ws/install_isolated/include
 /usr/include/c++/4.8
 /usr/include/i386-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/i686-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/i686-linux-gnu/4.8/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include
End of search list.
GNU C++ (Ubuntu 4.8.5-2ubuntu1~14.04.1) version 4.8.5 (i686-linux-gnu)
	compiled by GNU C version 4.8.5, GMP version 5.1.3, MPFR version 3.1.3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 0603886523ce76985a8d2b2a7d22cd38
In file included from domain.cpp:1:0:
domain.cpp:4:5: error: expected unqualified-id before numeric constant
 int DOMAIN = 3;
     ^
Comment 1 Markus Trippelsdorf 2016-07-18 07:07:11 UTC
What do you expect? Just use a different variable name.
Comment 2 Jakub Jelinek 2016-07-18 07:45:37 UTC
First of all, note that math.h header comes from the C library, not GCC, so likely glibc in your case.
And, please learn about Feature Test Macros that affect the namespace.
DOMAIN is part of SVID support, is included in e.g. _DEFAULT_SOURCE or _GNU_SOURCE.  So e.g. if you compile with -D_XOPEN_SOURCE=700 or various others, DOMAIN will not be visible.
Comment 3 henad221 2016-07-18 08:01:50 UTC
Thanks for quick reply. I didn't expect the name DOMAIN to be used by something when including math.h. Thanks to Jakub for an explanation of what is happening, next time I will try to dig more into these kinds of issues before posting it as a bug.