LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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
 
Search this Thread
Old 07-29-2005, 12:04 PM   #1
lyd
LQ Newbie
 
Registered: Jul 2005
Posts: 9

Rep: Reputation: 0
"...incompatible pointer type" Can it be ended?


Its probably been asked and answered so many times now that only the last
several responsesare coming up on the search button, and those are direct
answers to offshoot problems that include this warning in their compilations,
I want to know, once and for all, what the compiler does this for. Can someone
please post this? Right now, for the sake of simplicity ive got this example:

main (int argc, char **argv[])
{
char *instr;
instr = argv[1];
printf("%s\n", instr);
}

It does its job just fine, but its got that obnoxious warning, why?

Last edited by lyd; 07-29-2005 at 12:17 PM.
 
Old 07-29-2005, 12:22 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Code:
main (int argc, char **argv[])
The second parameter in main() is a NULL-terminated array of strings. Hence, you can declare it as char *argv[] or char **argv, but not char **argv[] like you have it.
 
Old 07-29-2005, 02:28 PM   #3
lyd
LQ Newbie
 
Registered: Jul 2005
Posts: 9

Original Poster
Rep: Reputation: 0
But the song remains the same, actually, it just got worse, your
suggestion compiles into a segmentation fault;
i sure would like to know <b>why</b>.

<code>
char *foo
</code>
i believe this is a memory address reservation with room
for one addresses as long as one byte
<code>
char foo[]
</code>
this is an illegal declaration for a good reason, finite
memory, plus there are other processes in that memory
that have to leave eachother alone if the system is to keep
running. side note, declaring main(char foo[]) will compile
where as main() { char foo[]; } will not.

ive tried about 4 of the 8 possible *foo[]/*var || foo[]/var
assignments, and so far i cant make any of the main (char foo[])s
do anything other than cause a segmentation fault, if i find something
ill ammend my post

Last edited by lyd; 07-29-2005 at 02:31 PM.
 
Old 07-29-2005, 02:43 PM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
I'm not sure why it's not working for you:
Code:
itsme@itsme:~/C$ cat arg1.c
#include <stdio.h>

int main (int argc, char *argv[])
{
char *instr;
instr = argv[1];
printf("%s\n", instr);
return 0;
}
itsme@itsme:~/C$ gcc -Wall arg1.c -o arg1
itsme@itsme:~/C$ ./arg1 "this is arg1"
this is arg1
itsme@itsme:~/C$
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
C error "dereferencing pointer to incomplete type" lucs Slackware 6 02-21-2005 09:33 AM
How does one surpress incompatible pointer type warnings? tonyfreeman Programming 1 08-18-2004 06:06 PM
curl "incompatible pointer type" while making PHP basse- Linux - Software 2 04-15-2004 10:21 AM
Getting an incompatible pointer type error... JStew Programming 4 03-06-2003 05:08 PM
Installing Wine - incompatible pointer type orange400 Linux - Software 1 03-03-2003 12:57 AM


All times are GMT -5. The time now is 07:59 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 Google+: linuxquestions
Open Source Consulting | Domain Registration