[LCP] Struggling with Pointers
Paul Otheim
coriolis220 at gmail.com
Sat Jan 16 11:50:20 EST 2010
On Fri, Jan 15, 2010 at 4:03 PM, Christopher Howard <choward at indicium.us>wrote:
> Paul Otheim wrote:
>
> > gcc -o insert insertEntry.c
> > insertEntry.c:8: warning: ‘struct entry’ declared inside parameter list
> > insertEntry.c:8: warning: its scope is only this definition or
> > declaration, which is probably not what you want
> > insertEntry.c: In function ‘main’:
> > insertEntry.c:20: error: conflicting types for ‘insertEntry’
> > insertEntry.c:8: note: previous definition of ‘insertEntry’ was here
> >
> >
> > void insertEntry (struct entry *new, struct entry *here) //this is line 8
> > {
> > .....
> > }
> >
> > int main (void)
> > {
> > void insertEntry (struct entry *new, struct entry *here); // this is
> > line 20
> >
> > ......
> > }
> >
>
> No, the prototype for your function doesn't go inside another function.
> (Main is a function.)
>
> If you have declared insertEntry() in the same file, previous to the
> place where you intend to use it, you don't actually need a function
> prototype. Function prototypes are for if you want to use a function
> before you have actually defined what it does internally. Function
> prototypes usually go in header files.
>
> It also appears that you have not coded a definition for "struct entry"
> before line 8, which is confusing the compiler. See any tutorial on C
> structs.
>
>
Do you hear that? It's the sound of me kicking myself!
Thanks for your help. Just to clarify. I had declared struct entry in main()
being under the impression for some reason that it would then be available
to all functions. So if I understand correctly I have to declare it outside
of main() which makes it a global definition. Would it then be global to all
files linked to this file?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.linux.org.au/pipermail/linuxcprogramming/attachments/20100115/0ae59a8b/attachment-0001.htm
More information about the linuxCprogramming
mailing list