Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > [newbie]:function returns a pointer to a string

Reply
Thread Tools

[newbie]:function returns a pointer to a string

 
 
uy do
Guest
Posts: n/a
 
      10-16-2003
Hi,
I see a function but I dont white understand a few things. So please help me
to clear it out.
The code is as follow
-------------
//global variable
char buf[32768];

char * myfunc(s1)
char *s1;
{
//definition of the function
return (buf);
}
-------------
My questions is why don't they define the function as simple as char
*myfunc(char *s1) ?


 
Reply With Quote
 
 
 
 
Tristan Miller
Guest
Posts: n/a
 
      10-16-2003
Greetings.

In article <(E-Mail Removed)>, uy do wrote:
> char * myfunc(s1)
> char *s1;
> {
> //definition of the function
> return (buf);
> }
> -------------
> My questions is why don't they define the function as simple as char
> *myfunc(char *s1) ?


This is old-style (K&R) C, which predates the ANSI/ISO standards. Nowadays
the equivalent syntax you suggested is preferred, and all modern compilers
support it.

This question is also answered in the FAQ.

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      10-16-2003
uy do <(E-Mail Removed)> scribbled the following:
> Hi,
> I see a function but I dont white understand a few things. So please help me
> to clear it out.
> The code is as follow
> -------------
> //global variable
> char buf[32768];


> char * myfunc(s1)
> char *s1;
> {
> //definition of the function
> return (buf);
> }
> -------------
> My questions is why don't they define the function as simple as char
> *myfunc(char *s1) ?


It's an old K&R style definition. It's more or less the same. Not
exactly the same though - the way it handles argument promotions
differs. I don't remember exactly how it differs. K&R style definitions
are still valid in standard C, but deprecated. <OT>C++ does not allow
K&R style definitions.</OT>

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"C++ looks like line noise."
- Fred L. Baube III
 
Reply With Quote
 
uy do
Guest
Posts: n/a
 
      10-16-2003
Thanks,
~Uy
"Joona I Palaste" <(E-Mail Removed)> wrote in message
news:bmme2k$m6s$(E-Mail Removed)...
> uy do <(E-Mail Removed)> scribbled the following:
> > Hi,
> > I see a function but I dont white understand a few things. So please

help me
> > to clear it out.
> > The code is as follow
> > -------------
> > //global variable
> > char buf[32768];

>
> > char * myfunc(s1)
> > char *s1;
> > {
> > //definition of the function
> > return (buf);
> > }
> > -------------
> > My questions is why don't they define the function as simple as char
> > *myfunc(char *s1) ?

>
> It's an old K&R style definition. It's more or less the same. Not
> exactly the same though - the way it handles argument promotions
> differs. I don't remember exactly how it differs. K&R style definitions
> are still valid in standard C, but deprecated. <OT>C++ does not allow
> K&R style definitions.</OT>
>
> --
> /-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
> \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
> "C++ looks like line noise."
> - Fred L. Baube III



 
Reply With Quote
 
Irrwahn Grausewitz
Guest
Posts: n/a
 
      10-16-2003
"uy do" <(E-Mail Removed)> wrote:

<snip>
>char * myfunc(s1)
> char *s1;
> {

<snip>
>My questions is why don't they define the function as simple as char
>*myfunc(char *s1) ?


It's just an old-style function definition.

Regards
--
Irrwahn
((E-Mail Removed))
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointer to an array vs pointer to pointer subramanian100in@yahoo.com, India C Programming 5 09-23-2011 10:28 AM
Pointer to pointer or reference to pointer A C++ 7 07-05-2011 07:49 PM
Pointer to pointer Vs References to Pointer bansalvikrant@gmail.com C++ 4 07-02-2009 10:20 AM
passing the address of a pointer to a func that doesnt recieve a pointer-to-a-pointer jimjim C Programming 16 03-27-2006 11:03 PM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM



Advertisments