How to define an external macro.....

Your source for all things Atmel.
Locked
User avatar
SebaS
Posts: 75
Joined: Mon May 22, 2006 10:02 am
Location: Argentina

How to define an external macro.....

Post by SebaS » Wed Jun 21, 2006 11:27 am

Hi! I'm back in town!!

I'm not much of a C programmer so I'm having some troubles....

I'got a macro and i want to use it in another module. How can I do it??

#define WEN var1

that's in module1.h

and I want to use WEN in module2.h

And I can't do it!!! :cry:

Any help is helpful :wink: [/code]

jasonharper
Posts: 312
Joined: Wed Mar 02, 2005 12:14 pm
Location: Oklahoma
Contact:

Post by jasonharper » Wed Jun 21, 2006 11:44 am

You'd need to put:

Code: Select all

#include "module1.h"
somewhere in module2 prior to the point at which you first use the macro.

User avatar
SebaS
Posts: 75
Joined: Mon May 22, 2006 10:02 am
Location: Argentina

Post by SebaS » Thu Jun 22, 2006 5:17 am

Yes; I try to do that but an error flashes. And it's because I use functions from modulo2 in modulo1 and it says that there is an "ilegal function redefinition".
Believe me I'm getting MAD :twisted:

jasonharper
Posts: 312
Joined: Wed Mar 02, 2005 12:14 pm
Location: Oklahoma
Contact:

Post by jasonharper » Thu Jun 22, 2006 6:02 am

Are you putting actual functions (not just function declarations) in your *.h files?

The normal structure for a multi-file C program is to have all functions in *.c files, each of which (except maybe for the top-level file) having a corresponding *.h file with declarations for the public functions & variables actually defined in the *.c file. Each *.c file #includes its own header file at the very top, along with the headers for each other *.c file containing items it references.

Locked

Return to “Code”