Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   from void * to C string? (http://www.programmingforums.org/showthread.php?t=15248)

null_ptr0 Feb 23rd, 2008 7:18 PM

multiple definition of variable
 
DevCpp with g++ is giving me errors about 3 of my variables declared in a header as multiple definitions, even though I use the #ifndef preprocessor command correctly.
Any help?

note: it occurs during link time

Sane Feb 23rd, 2008 7:23 PM

Re: from void * to C string?
 
(Edit: Fine, change your quesiton on me.)

Here it is in C. I'm not sure if C++ has different rules regarding void pointer typecasting, but hopefully it can be of use until someone else fills in the details for me.

:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void outstring(void *p) {
  5.     char *s = (char *)p;
  6.     printf("%s\n", s);
  7. }
  8.  
  9. int main() {
  10.     outstring("Hello World!");
  11.     return 0;
  12. }


null_ptr0 Feb 23rd, 2008 7:33 PM

Re: from void * to C string?
 
Quote:

Originally Posted by Sane (Post 141430)
Here it is in C. I'm not sure if C++ has different rules regarding void pointer typecasting, but hopefully it can be of use until someone else fills in the details for me.

:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void outstring(void *p) {
  5.     char *s = (char *)p;
  6.     printf("%s\n", s);
  7. }
  8.  
  9. int main() {
  10.     outstring("Hello World!");
  11.     return 0;
  12. }


fixed that with a dumb fix: i was suppose to use static_cast. new error now.

grumpy Feb 24th, 2008 12:49 AM

Re: from void * to C string?
 
If you want useful help, it is generally a good idea to provide information about what your problem actually is. For example, what error messages you are getting, and what compiler (or linker) is generating them?

Changing your question while someone is in the process of providing an answer to your original question is rather pointless too.

null_ptr0 Feb 24th, 2008 9:34 AM

Re: from void * to C string?
 
Quote:

Originally Posted by grumpy (Post 141442)
If you want useful help, it is generally a good idea to provide information about what your problem actually is. For example, what error messages you are getting, and what compiler (or linker) is generating them?

Changing your question while someone is in the process of providing an answer to your original question is rather pointless too.

its okay, i finished it anyway. it was an error where i was including a header in two files, which were both being included into the same file. all's fixed. can someone lock?


All times are GMT -5. The time now is 12:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC