Pages: 1 [2]   Go Down
Author Topic: multiple definition of ...  (Read 4957 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3418
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm. I tried to boil it down to the following:

Code:
#include <bar.h>
#include <foo.h>

int main(){}

Code:
#ifndef bar
#define bar

#include <foo.h>

#endif

Code:
#ifndef foo
#define foo

void f();
int x = 0;

#endif

This does compile --> I thought I understood it. Everything works but I would expect a compiler error. --> I can not reproduce the issue I was asking about. But obviously I still do not understand it.

In my understanding both foo and bar should contain a definition. Hence they should create a compiler error when I include both of them. Obviously they do not. Any hints on this? Did I understand it wrong again or is this something else I do not know?
« Last Edit: September 26, 2009, 10:32:06 am by udoklein » Logged

Check out my experiments http://blog.blinkenlight.net

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What happens if you try to use x in you main() ?

BTW, foo will not be included twice, because of the inclusion guard (#ifndef/#define), this is acutally its purpose.
Logged

Pages: 1 [2]   Go Up
Jump to: