Varargs Issue

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pranjas
Member
Member
Posts: 25
Joined: Sun Jan 16, 2011 9:18 pm

Varargs Issue

Post by pranjas »

Hi
I was coding the printk routine for which i needed the varargs. As mentioned in one of the printing tutorials on this website it uses gcc's in built version.

Code: Select all

#define va_start(v,l) __builtin_va_start(v,l)
#define va_arg(v,l)   __builtin_va_arg(v,l)
#define va_end(v)     __builtin_va_end(v)
#define va_copy(d,s)  __builtin_va_copy(d,s)
typedef __builtin_va_list va_list
The problem is as soon i insert this code i get a weird error

Code: Select all

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’
Any thoughts on how to get it working. I tried one of the other implementations which is here,

Code: Select all

typedef char* va_list;

#define _INTSIZEOF(n)   ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )

#define va_start(ap,v)  ( ap = (va_list)&v + _INTSIZEOF(v) )

#define va_arg(argp,type) (*(type *)(((argp) +=_INTSIZEOF(type))-_INTSIZEOF(type)))

#define va_end(x) (x=(void*)0)
but this implementation isn't working for me at least with gcc.
I've gcc version 4.4.1 OpenSuse11.2 for developing the kernel.
kriscrump
Posts: 5
Joined: Mon Jan 31, 2011 9:13 am

Re: Varargs Issue

Post by kriscrump »

pranjas wrote:

Code: Select all

typedef __builtin_va_list va_list
The problem is as soon i insert this code i get a weird error

Code: Select all

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘extern’
Any thoughts on how to get it working. I tried one of the other implementations which is here,
I'm not sure if this might be a problem, but shouldn't the aforementioned line of code end with a ';'? Maybe this will fix it? Unless it was just a mistake in typing it into osdev's editor?

Regards,
~Kris
mariuszp
Member
Member
Posts: 587
Joined: Sat Oct 16, 2010 3:38 pm

Re: Varargs Issue

Post by mariuszp »

i think i understand your mistake.

If you use a compiler directive (one that starts with '#'), then the line does not need to end with ';', so:

Code: Select all

#define HI 0x555
is valid syntax. However, 'typedef' is technically not a compiler directive. So this:

Code: Select all

typedef char*  va_list
is invalid. You must add a ';' at the end, like this:

Code: Select all

typedef char * va_list;
I had these kinds of problems all the time. Hope I helped :)
pranjas
Member
Member
Posts: 25
Joined: Sun Jan 16, 2011 9:18 pm

Re: Varargs Issue

Post by pranjas »

:oops: !... yeah there's no ; after the typedef.

thanks... i guess worrying too much about bigger problems i'm facing couldn't notice this small mistake...
really embarassed
Post Reply