Jump to content
  • Advertisement
Sign in to follow this  
_Sigma

At a loss with printf...

This topic is 4229 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright, humbling question:
char* str1 = "Chris";

..set obj to point to str1 ...

printf("Index %d is %s ",i,*(char*)hash->HT.elms.obj);

Where obj is a void*. This works if I use ints (and change the nessessary params), but just up and seg faults with char* s. Any help would be slick, as I know its something stupid, but I dunno...lets blame it on being sleepy :P

Share this post


Link to post
Share on other sites
Advertisement
*(char*)hash->HT.elms.obj
|
\--- Right here is where you dereference obj from (char *) to char. That means its no longer pointing to an array of chars. Take that out and it should work.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
I would argue that one is always "at a loss" when one uses printf(), and this is one reason why. :)


Well in C it's pretty much the best there is, and we have no reason to assume he isn't using C (didn't tell us the language, the code is valid C and printf is in namespace std in C++). If you're arguing that C++ streams are better than printf, then printf does also have some advantages over C++ streams* (which is one of the reasons for Boost.Format).

* Herb Sutter wrote something about it here and Andrei Alexandrescu here

Share this post


Link to post
Share on other sites
my compiler (g++) tells me when I pass a string but should be passing an int or whatever. So type safety is a redundant argument too imo.

Share this post


Link to post
Share on other sites
Quote:
Original post by Genjix
my compiler (g++) tells me when I pass a string but should be passing an int or whatever. So type safety is a redundant argument too imo.
Good luck getting any of those warnings to fire off when the format string isn't hard-coded.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!