OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 2:30 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: macro expansion expected but failed by gcc
PostPosted: Wed Jun 03, 2020 3:42 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
My header file (low_level.h)

Code:
#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


my library implementation source file (low_level.c)
Code:
#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));
}


my main.c

Code:
#include "low_level.h"
#include <stdio.h>

void main(){
      port_byte_out(0x10, 14);
      outb(0x10,14);
}


compile with gcc gives me linking error indicating symbol outb not found.. but isn't it a macro
which gcc should expand?


Top
 Profile  
 
 Post subject: Re: macro expansion expected but failed by gcc
PostPosted: Wed Jun 03, 2020 4:29 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Well....

You've wrapped your header file in
Code:
#ifdef LOW_LEVEL_H
...
#endif

LOW_LEVEL_H isn't defined, so the header never gets included. You'll also note the mistake in the second line of your header.

This explains your initial problem, but fixing it then throws up a further one. I think it's a useful exercise for you to try to solve that one yourself.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 275 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group