veryBadProgrammer
veryBadProgrammer

Reputation: 115

SYNTAX: what is the correct way to do a forward declaration for a c function?

I am currently tasked with getting code from one device to run on another and have a snippet of the functionality which means I need to shut down or feed the interfaces that are not being fed due to the cutting out of this module. When trying to compile I'm running into a syntax error that baffles me.

In a .h file I found a forward declaration at global scope like this:

void INT_CODE_ATTR fatal_error (unsigned char error_module, unsigned short error_line);

Where INT_CODE_ATTRwas not defined. Since I don't know what it could/should be I did this:

#define INT_CODE_ATTR
void INT_CODE_ATTR fatal_error (unsigned char error_module, unsigned short error_line);

This gave me the error:

error: declaration does not declare anything [-fpermissive]

So I changed ; to {} resulting in this error:

error: expected unqualified-id before '{' token

I thought it had to have something to do with INT_CODE_ATTR so I commented it out, but the error persists. Also the whole line is underlined (in Eclipse) and it tells me just: "Syntax Error".

Just to clarify, my last attempt at solving this looked like this:

#define INT_CODE_ATTR
void /*INT_CODE_ATTR*/ fatal_error (unsigned char error_module, unsigned short error_line) {}

Upvotes: 1

Views: 79

Answers (1)

Goswin von Brederlow
Goswin von Brederlow

Reputation: 12332

The code sniplet you gave works just fine. Nothing wrong there (once you defined INT_CODE_ATTR).

Run gcc -E or your compilers equivalent to see what the pre-processor makes out of your actual code. What the actual compiler gets is not what you wrote, something is messing up the input.

Upvotes: 3

Related Questions