0

I am working on a microcontroller project in C. The main.c file includes a header defining all of the registers as structures and chars. Unfortunately they name the registers unmeaning-full names like PORTA. Is it possible to rename the structures and variable defined in the header file to something more meaningful in my main file?

So instead of PORTA I can call it OUT without modifying the header file where it was defined.

jcb344
  • 323
  • 5
  • 16
  • 8
    Macros? `#define OUT PORTA` – Mysticial Jan 14 '12 at 21:21
  • @Mystical Macros can be tricky here -typedef is the way to go http://stackoverflow.com/questions/3263252/is-typedef-just-a-string-replacement-in-code-or-somethings-else/3263326#3263326 – Amarghosh Jan 14 '12 at 21:24
  • 4
    @Amarghosh Although it's not clear from the question, I have a feeling that they might actually be variable names rather than types. – Mysticial Jan 14 '12 at 21:27
  • Which micro and which compiler? Often there is platform specific ways. – Roland Rabien Jan 14 '12 at 21:48
  • 2
    Considering that the names correspond to specific registers/memory locations, I think it's very likely they're variable names rather than types. – Dmitri Jan 14 '12 at 21:56
  • You are correct, They are variable names. It is the PIC18 C compiler from Microchip. – jcb344 Jan 17 '12 at 00:20

2 Answers2

5

Promoting comment to answer:

The easiest way I can think of is to just use macros:

#define OUT PORTA

And these don't need to be in the header.

EDIT :

If the original names are actually names of variables (rather than types), then this is the way to go since the typedef method will not work.

Mysticial
  • 464,885
  • 45
  • 335
  • 332
3

You can use typedef to create an alias:

typedef PORTA OUT;
undur_gongor
  • 15,657
  • 5
  • 63
  • 75
Chris
  • 908
  • 6
  • 11