Skip to contentSkip to conversation

MIsc C programming questions

DISCUSSION fabio 2 participants 2 messages Oct 24, 2005

lore
Share & tools
lore

fabio

author
#0 lore raw

Hello,

I have some questions about C programming not exactly on Linux but Solaris, I hope you can help me:

- Why I cant include this __asm___ lines on a C program and compile it on Sun cc on Solaris 10?

-bash-3.00$ cat ret.c; cc ret.c
/*

*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/systeminfo.h>

/*
*
*/
int
main() {
int ret;
ret = get_sp();
printf("Stack Pointer is: 0x%x\n",ret);
char platform[257],release[257]; sysinfo(SI_PLATFORM, platform, sizeof(platform) - 1); sysinfo(SI_RELEASE, release, sizeof(release) - 1); printf("Platform: %s (%s)\n", platform, release); return (EXIT_SUCCESS);
}

int
get_sp(){
__asm__("mov %sp,%g1");
__asm__("mov %g1,%o1");
}
"ret.c", line 16: warning: implicit function declaration: get_sp "ret.c", line 27: warning: implicit function declaration: __asm__
Undefined first referenced
symbol in file
__asm__ ret.o
ld: fatal: Symbol referencing errors. No output written to a.out -bash-3.00$

Any workaround?

Thanks

#1 lore raw
Quoted 7 lines · fabio

Hello,

I have some questions about C programming not exactly on Linux but Solaris, I hope you can help me:

- Why I cant include this __asm___ lines on a C program and compile it on Sun cc on Solaris 10?

Because Sun's C compiler doesn't support __asm__ which is a GNU extension.

Quoted 1 line

Any workaround?

Use the asm keyword instead:

	asm("mov %sp,%g1");
	asm("mov %g1,%o1");

Does it help?

\Steve