~ > gcc foo.c -o foo
~ > and
~ > gcc -S foo.c
~ > gcc foo.s -o foo
~ >
~ > should produce similar (well almost) code. However, when in latter case I
~ > run foo, I get Bus error(core dumped) message. Ideas what goes wrong here?
~ > I think that's something to do with alignment, but not sure.
~
~ Odd. Try adding `-g' to both commands and running the resulting
~ program under gdb.
~
bash-2.01$ gcc -S -ggdb foo.c
foo.c: In function `main':
foo.c:5: warning: initialization makes integer from pointer without a cast
foo.c:6: warning: initialization makes integer from pointer without a cast
bash-2.01$ gcc foo.s -o foo.gdb
bash-2.01$ ./foo.gdb
Bus error (core dumped)
bash-2.01$ gdb foo.gdb foo.gdb.core
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.16 (i386-unknown-freebsd),
Copyright 1996 Free Software Foundation, Inc...
Core was generated by `foo.gdb'.
Program terminated with signal 10, Bus error.
Cannot access memory at address 0x20015080.
#0 0x20068c8e in ?? ()
(gdb) where
#0 0x20068c8e in ?? ()
#1 0x2007d060 in ?? ()
#2 0x2005c456 in ?? ()
#3 0x1646 in main () at foo.c:8
(gdb)
here's the code itself:
#include <stdio.h>
void main()
{
char foo="bababa";
char bar="hello world";
printf(" foo %s\n",foo);
printf("%s",bar);
printf("boom34");
}
---
actually I noted that this piece gives bus error, even when compiling
directly.. but what's wrong here?