Question

I'm working on two different LCD initializations. One is from the Professor's hardware and the other one is mine. I want to switch between two functions using macro definitions:

#ifndef LCD_Professor

void InitLCD (uint8_t N, uint8_t F, uint8_t D, uint8_t C, uint8_t B, uint8_t ID, uint8_t SH) {
 ...
}

#endif

#ifndef LCD_Group3

void InitLCD (uint8_t N, uint8_t F, uint8_t D, uint8_t C, uint8_t B, uint8_t ID, uint8_t SH) { 
...
}

#endif

I was hoping that if I used #define LCD_Group3 in the beginning of the file, I could choose between both functions. Truth is, I never really worked with these macros. Should this work? or rather, is there any other way to do this?

Thanks!

Was it helpful?

Solution

It should be

#ifdef LCD_Professor
...
#endif

#ifdef LCD_Group3
...
#endif

Not #ifndef to choose which one of them you want to use, then you can do #define LCD_Group3 or LCD_Professor before you include the file, to enable one or the other.

OTHER TIPS

Must you use a macro? An alternative is to put the two functions in separate files and build only the one you want. Or even build both to different executable files and select the one you want when you run it.

If you are not familiar with building such things, you need a Makefile (a file with the name Makefile). For example, to build two applications 'prof' and 'stud' from a common file app.c and your two implementations in prof.c and stud.c :-

all: stud prof
CFLAGS = -g -Wall
CC = gcc

prof: prof.o app.o
        $(CC) $^ -o $@

stud: stud.o app.o
        $(CC) $^ -o $@

Note that there is a TAB before each $(CC), not spaces

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top