LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-29-2004, 01:56 PM   #1
bcf2
Member
 
Registered: Nov 2003
Location: Nowhere and somewhere
Distribution: Mandrake 10
Posts: 124

Rep: Reputation: 15
pointer from integer without a cast


can someone please help me in getting rid of this horrible message when compiling! What does it mean?!?
 
Old 12-29-2004, 02:25 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 53
It means exactly what it says. You're trying to use an integer as a pointer without a cast. We can't help you get rid of it unless you show us what the offending line of code is.
 
Old 12-29-2004, 02:29 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,524

Rep: Reputation: 93
It means there is some integer is used in the code where the compiler would expect a pointer.

Please post some code where the error occurs. Your question sounds like a letter sent to a mechanic asking: "The engine of my car doesn't run. How can I fix this please?".
 
Old 12-29-2004, 05:02 PM   #4
bcf2
Member
 
Registered: Nov 2003
Location: Nowhere and somewhere
Distribution: Mandrake 10
Posts: 124

Original Poster
Rep: Reputation: 15
The code is in the function fopen(Const char *path, const char *mode), I'me trying to have the first argument of the function be supplied by another function that returns an integer, and that is where I get the error. So the question is: How do I turn an int into a pointer?
ps: sorry for the confusion :-(
 
Old 12-29-2004, 05:10 PM   #5
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 53
I think the question should be "why are you passing an integer as the first argument to fopen()?"

I can't imagine what you're trying to do as being correct, but you could do it something like this: fopen((char *)func_returning_int(), "r");

I'm afraid to ask what the function returning the int is/does.
 
Old 12-30-2004, 06:55 AM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,524

Rep: Reputation: 93
Quote:
Originally posted by bcf2
The code is in the function fopen(Const char *path, const char *mode), I'me trying to have the first argument of the function be supplied by another function that returns an integer
Trying to further explain what itsme86 already said:

The function prototype you posted says that the first argument should be a pointer to char ("const char *path"), which is quite different from a pointer to int!

If you even manage to get it to compiled without errors (itsme86's example may do that), you'll have a huge bug in your code you won't get away with. If you're lucky, you'll get a runtime error (segmentation fault). If not, your program will behave very bad in an unpredictable way. Best-case scenario being fopen() returning an error indicating "File not found". When fopen() the file for writing, or worse: creating, things may get really bad, especially if you run it as root (don't try!).

Last edited by Hko; 12-30-2004 at 07:03 AM.
 
Old 12-30-2004, 11:26 AM   #7
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 45
Quote:
Originally posted by Hko
When fopen() the file for writing, or worse: creating, things may get really bad, especially if you run it as root (don't try!).
Yet another good reason not to run as root (that's one I hadn't really thought of). Such a mistake could be called a security hole, since it potentially allows the process to do stuff it shouldn't be doing.

But yeah, you definitely need to think this through. You're trying to ask fopen() to open a file with a name that is an integer? If you really want to open a file called "12345", then you should do some kind of string conversion (using sprintf() or the like) to convert that raw integer into a character string representing that number.
 
Old 12-30-2004, 02:04 PM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,524

Rep: Reputation: 93
Quote:
Originally posted by wapcaplet
Yet another good reason not to run as root (that's one I hadn't really thought of). Such a mistake could be called a security hole,
If you open a file for writing this way, it's potentionally worse than a security hole.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison between pointer and integer ---> WHY?? its_godzilla Programming 10 01-28-2005 09:40 PM
makes pointer from integer without a cast ? hubabuba Programming 2 01-28-2005 05:28 PM
makes pointer from interger without a cast y0shi Linux - General 4 10-21-2004 08:17 PM
Passing arg 3 of blah makes pointer from integer without a cast xconspirisist Programming 6 08-22-2004 08:04 AM
pointer to bog standard integer acid_kewpie Programming 4 02-02-2002 03:14 PM


All times are GMT -5. The time now is 06:48 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration