weird error when calling extern "c" from C++
Posted: Mon Jul 09, 2007 6:54 am
I'm getting these errors:
Both errors point to the line:
Here is my port.h:
and here is my port.cpp:
It's being passed to gcc using
I don't understand why it's doing this. I've used C in C++ before.
Code: Select all
port.cpp: In member function 'unsigned char Port::InByte(short unsigned int)':
port.cpp:16: error: expected unqualified-id before string constant
port.cpp: In member function 'void Port::OutByte(short unsigned int, unsigned char)':
port.cpp:25: error: expected unqualified-id before string constant
Code: Select all
extern "C"
Code: Select all
#ifndef PORT_H
#define PORT_H
class Port
{
public:
Port();
~Port();
unsigned char InByte(unsigned short _port);
void OutByte(unsigned short _port, unsigned char _data);
private:
};
extern Port port;
#endif
Code: Select all
#include "port.h"
Port port;
Port::Port()
{
}
Port::~Port()
{
}
unsigned char Port::InByte(unsigned short _port)
{
unsigned char rv;
extern "C"
{
__asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
}
return rv;
}
void Port::OutByte(unsigned short _port, unsigned char _data)
{
extern "C"
{
__asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}
}
Code: Select all
gpp -c port.cpp -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions