Domanda

I know that people usually define macro with a single value, such as:

#define PIN0 0x01

but what does it mean by this one with multiple values?

#define POWER_UP 0x02, 0x01, 0x00, 0x01, 0xC9, 0xC3, 0x80

Supposedly, I need to send the packets 0x02, 0x01, 0x00.... sequentially. If not using this macro, I will probably use an array. However, the toolchain generate this macro to me but I don't know how to use this to send the packets. It doesn't look like the array definition of macro. Does anyone know how I shall use this?

È stato utile?

Soluzione

Not really sure what you're asking about the packets (some more code would help) but:

char vals[] = { POWER_UP };
size_t i;

for (i = 0; i < sizeof(vals); ++i) {
    /* do something with vals[i] */
}

Altri suggerimenti

//test.c
#define POWER_UP 0x02, 0x01, 0x00, 0x01, 0xC9, 0xC3, 0x80

POWER_UP

#only preprocessing
>gcc -E test.c
# 1 "test.c"
# 1 "<command-line>"
# 1 "test.c"


0x02, 0x01, 0x00, 0x01, 0xC9, 0xC3, 0x80

As you can see it will replace the macro will your list of values.

It simply expands to 0x02, 0x01, 0x00, 0x01, 0xC9, 0xC3, 0x80 whenever the POWER_UP macro is referenced.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top