LWN.net Logo

Hmm... Very simple test...

Hmm... Very simple test...

Posted Nov 3, 2011 13:20 UTC (Thu) by khim (subscriber, #9252)
In reply to: Simple by quotemstr
Parent article: libabc: a demonstration library for kernel developers

$ mkdir test1
$ mkdir test2
$ echo '#pragma once' > test1/test.h
$ echo 'abc' >> test1/test.h
$ cp -ai test1/test.h test2/test.h
$ echo '#include "test1/test.h"' > test.c
$ echo '#include "test2/test.h"' >> test.c
$ gcc -E test.c
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"
# 1 "test1/test.h" 1

abc
# 2 "test.c" 2
$ touch test2/test.h
$ gcc -E test.c
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"
# 1 "test1/test.h" 1

abc
# 2 "test.c" 2
# 1 "test2/test.h" 1

abc
# 2 "test.c" 2
$ gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 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.

This is just a preprocessor test, but compiler does the same thing.

Note that usually we do want this behavior (these files are identical - they come from the same source, after all) - and usually it works, but sometimes when you do complex manipulations (git in my case, but of course it's not the only possibility) everything blows up.

There is always a well-known solution to every human problem--neat, plausible, and wrong.

Well, "#pragma once" is such a solution - don't use it.


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds