From: Steve Graegert <graegerts@gmail.com>
To: James Colannino <james@colannino.org>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: How to prototype functions that return pointers
Date: Sat, 25 Jun 2005 08:56:52 +0200 [thread overview]
Message-ID: <6a00c8d50506242356dd6717a@mail.gmail.com> (raw)
In-Reply-To: <42BC7A4F.60304@colannino.org>
On 6/24/05, James Colannino <james@colannino.org> wrote:
> Ok, so this is a very embarassing question. I tried googling for the
> answer but haven't figured it out yet, and everything I've tried results
> in compilation errors. I want to prototype a function that takes nothing
> as an argument but returns a pointer to a character.
>
> I've tried the following:
>
> char * readline();
> char *readline();
I can't see a problem with this declaration, thus I am not able to
reproduce the error(s). What I see here is a function taking an
arbitrary number of arguments returning a pointer to a char.
> These first two result in 4 errors, each one identical and each one
> telling me "error: two or more data types in declaration of 'readline' "
>
> *char readline();
> * char readline();
This is obviously wrong because you're trying to dereference a data
type, not an identifier. Everything else that follows in this line is
discarded by the parser.
I have compiled three different function declarations that all have a
different meaning to help you understand what could have been wrong:
/* pointer to func() returning a char */
char (*func)();
/* function taking a char pointer and returning char-pointer */
char* f(char *);
/*
* pointer to a function taking pointer to a char,
* returning a pointer to a char
*/
char* (*fp)(char *);
Hope this clarifies the relations between pointers and functions and
their arguments.
Kind Regards
\Steve
--
Steve Graegert <graegerts@gmail.com> || <http://www.technologies.de/~sg/>
Independent Software Consultant {C/C++ && Java && .NET}
Mobile: +49 (176) 21 24 88 69
Office: +49 (9131) 71 26 40 9
next prev parent reply other threads:[~2005-06-25 6:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-24 21:25 How to prototype functions that return pointers James Colannino
[not found] ` <op.ssv8s2eyizdgzp@mail.nairnconsulting.ca>
2005-06-24 21:50 ` James Colannino
2005-06-25 6:22 ` wwp
2005-06-25 6:56 ` Steve Graegert [this message]
2005-06-26 3:36 ` Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6a00c8d50506242356dd6717a@mail.gmail.com \
--to=graegerts@gmail.com \
--cc=james@colannino.org \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.