macro expansion expected but failed by gcc
Posted: Wed Jun 03, 2020 3:42 am
My header file (low_level.h)
my library implementation source file (low_level.c)
my main.c
compile with gcc gives me linking error indicating symbol outb not found.. but isn't it a macro
which gcc should expand?
Code: Select all
#ifdef LOW_LEVEL_H
#define LOW_LEVEL
#define inb(p) port_byte_in(p)
#define outb(p, b) port_byte_out(p,b)
unsigned char port_byte_in(unsigned short port)
void port_byte_out(unsigned short port, unsigned char data)
#endif
Code: Select all
#include "low_level.h"
unsigned char port_byte_in(unsigned short port){
unsigned char result;
asm(" in %%dx, %%al":"=a"(result):"d" (port));
return result;
}
void port_byte_out(unsigned short port, unsigned char data){
asm("out %%al, (%%dx)"::"a"(data), "d"(port));
}
Code: Select all
#include "low_level.h"
#include <stdio.h>
void main(){
port_byte_out(0x10, 14);
outb(0x10,14);
}
which gcc should expand?