Mehdi Keddache wrote: > > Hello, I never could figure out why when you declare a variable like that > char *message; > and you use this variable in a printf you get a segfault > printf("this is the value of message: %s\r\n",message); the reason for this is because *message is a pointer to a character. the pointer, for most compilers is 4bytes sometimes 8. the character is 1 byte. when you include message like that in the printf statement, you are sending in the pointer value and type. the compiler doesnt care, it assumes you know what you want. when you get to the runtime and you havent taken precautions, BAM you get sprintf trying to access a memory location which holds a character value when it actuality it holds part of the value for a pointer. not knowing exactly how printf handles it, all you can assume is that you'll get undefined results(as the c gurus put it...) and you can expect improper memory access at best and a crash at worse. this is probably babblized, i'm tired, but i hope i helped clear it up just a bit. maybe some of the other heave C dudes can explain it a little better. -invincibill -- ** I truly believe that the internet will do more to bring about world peace than any other device in human history. ** http://www.ntsource.com/~long Myths of Time Mud telnet://206.152.243.1:4000 +-----------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://cspo.queensu.ca/~fletcher/Circle/list_faq.html | +-----------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/18/00 PST