Go Down

Topic: multiple definition of ... (Read 6 times) previous topic - next topic

Udo Klein

#15
Sep 26, 2009, 05:30 pm Last Edit: Sep 26, 2009, 05:32 pm by udoklein Reason: 1
Hmm. I tried to boil it down to the following:

Code: [Select]

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

int main(){}


Code: [Select]

#ifndef bar
#define bar

#include <foo.h>

#endif


Code: [Select]

#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?
Check out my experiments http://blog.blinkenlight.net

AlphaBeta

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.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview