Randomblue
Randomblue

Reputation: 116273

expected ‘;’ before numeric constant

When compiling the following program, I get the error expected ‘;’ before numeric constant . What am I doing wrong?

#include <stdio.h>

#define GPIOBase 0x4002 2000

uint32_t * GPIO_type(char type);

int main(void)
{
    GPIO_type('G');

    return 0;
}

uint32_t * GPIO_type(char type)
{
    return (uint32_t *) GPIOBase;
}

Upvotes: 2

Views: 6291

Answers (4)

Luchian Grigore
Luchian Grigore

Reputation: 258558

The code doesn't make sense.

Your compiler sees:

uint32_t * GPIO_type(char type)
{
    return (uint32_t *) 0x4002 2000;
}

which is illegal C syntax.

Upvotes: 0

Bo Persson
Bo Persson

Reputation: 92211

Expanding the macro, you get

return (uint32_t *) 0x4002 2000;

which isn't correct code.

Upvotes: 1

Moo-Juice
Moo-Juice

Reputation: 38825

The problem is:

#define GPIOBase 0x4002 2000

And where you use it:

return (uint32_t *) GPIOBase;

becomes:

return (uint32_t *) 0x4002 2000;

Which is a compiler error. There's a stray 2000 lingering after your 0x4002. I suspect you want:

#define GPIOBase 0x40022000

Upvotes: 7

Constantinius
Constantinius

Reputation: 35039

The Problem is this line:

#define GPIOBase 0x4002 2000

You are trying to define more than just a constant within the symbol GPIOBase. When the definition is applied, your function looks like this:

uint32_t * GPIO_type(char type)
{
    return (uint32_t *) 0x4002 2000;
}

Which is not valid C code.

Upvotes: 4

Related Questions