Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 10th, 2007, 2:37 PM   #11
colin mac
Newbie
 
Join Date: Nov 2007
Location: Ireland
Posts: 21
Rep Power: 0 colin mac is on a distinguished road
Re: Function returning double pointer ?

Isn't an empty parenthesis only the same as void in C++, whereas in C it implies that the function can take a number of arguments?
colin mac is offline   Reply With Quote
Old Dec 11th, 2007, 2:40 AM   #12
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Re: Function returning double pointer ?

Quote:
Originally Posted by xavier View Post
Ok, the method signatures are generated with rpcgen. So i'm not modifying them.
Now , it's all interesting and stuff , and I do appreciate you taking the time to answer Grumpy.

But the question is quite simple . How can I work with " char ** " method signatures ?
And that simple question is insufficient because you have given no information about what the functions with "char ** method signatures" are required to do. Stating that they are generated by rpcgen gives no useful information whatsoever.

I do happen to know that rpcgen is a pre-compiler for a sun-proprietary rpc (remote procedure call) interface specification. To answer your question, I would have to see some information about your interface specification, learn the rpc language and learn about workings of the (proprietary) rpgen compiler. Pay me the going rate -- which applies to clients who expect the impossible from nothing -- of US$1000 (with a minimal non-refundable deposit in advance equivalent to 40 hours) and I'll think about it.....maybe.

You might have more luck by following simple advice: RTFM to learn about rpc and rpcgen for yourself.
grumpy is offline   Reply With Quote
Old Dec 11th, 2007, 4:32 AM   #13
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 406
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
Re: Function returning double pointer ?

Ok mate, don't get all angry there. I thought that a signature like
char ** methodname () , is not such an uncommon thing in c, and that a simple and precise answer exists.

Don't feel like you HAVE to answer . It's a forum, if you want to answer then do it , otherwise don't .

Ps : To me , the question seemed easy enough . Given a method signature like :
char ** method(){} how do I return and use a " char * " variable.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Dec 11th, 2007, 7:14 AM   #14
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Re: Function returning double pointer ?

And you have just demonstrated the art of asking a simple question that is completely meaningless.

Your question is like "how do I work with a stick?". There are many answers, depending on what you want to do with it. You can hit someone with it (a thought that tempts me mightily at the moment). You can throw it. You can carve it into a statue. You can burn it. You can dig a hole with it. You can use it to stir soup.

There is not a single answer to your question, unless you specify what the caller expects to do with the result returned by your function. You have not provided any such information, so there are many ways to "work with a method with a char ** return type".
grumpy is offline   Reply With Quote
Old Dec 11th, 2007, 2:13 PM   #15
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 406
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
Re: Function returning double pointer ?

Ok, the answer .. doesn't even matter anymore but if I can make grumpy undestand what I'm asking I'll have learned at least one thing .

So. From a function like : char ** ReturnString(){} I want to return a string. Then print the string on the screen.

Let's say that I only have this function and main. That's all. Can I be anymore clear ?
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Dec 11th, 2007, 4:36 PM   #16
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
Re: Function returning double pointer ?

>Can I be anymore clear ?
Clear as mud. Why would you want to do such a thing? The "why" usually results in a clearer requirement and that quickly brings you to the "how". As it is, I could do anything to meet your requirement, such as:
c Syntax (Toggle Plain Text)
  1. #include <stdio.h>
  2.  
  3. char **foo ( void )
  4. {
  5. static char *bar[] = { "a string" };
  6.  
  7. return &bar[0];
  8. }
  9.  
  10. int main ( void )
  11. {
  12. puts ( *foo() );
  13.  
  14. return 0;
  15. }
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old Dec 12th, 2007, 11:54 PM   #17
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 406
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
Re: Function returning double pointer ?

Ok, thanks for the answer.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Dec 14th, 2007, 6:44 PM   #18
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Re: Function returning double pointer ?

Narue's answer is one of many valid possibilities, but you still need to realise that it depends on how you call it. For example, a simple change of main() to;
int main(void)
{
    puts( *(foo() + 2));
    return 0;
}
will yield undefined behaviour (implicitly assuming the static array has more elements than it does). Which comes back to why I was asking what you expect the function to do.
grumpy is offline   Reply With Quote
Old Dec 18th, 2007, 12:00 PM   #19
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
Re: Function returning double pointer ?

Quote:
Originally Posted by colin mac View Post
Isn't an empty parenthesis only the same as void in C++, whereas in C it implies that the function can take a number of arguments?

In C: int foo(); as a function declaration
does mean there is no parameter specification, which then means you can call foo with different numbers of arguments of differing datatypes and not have the compiler complain. You'll see examples of this in the C99 standard especially with regard to function pointers. The standards are merely showing what is allowed. It's not necessarily a good thing to do.
jim mcnamara is offline   Reply With Quote
Old Dec 18th, 2007, 1:40 PM   #20
mbd
Programmer
 
Join Date: Nov 2007
Posts: 86
Rep Power: 2 mbd is on a distinguished road
Re: Function returning double pointer ?

Quote:
Originally Posted by Narue View Post
>
c Syntax (Toggle Plain Text)
  1. return &bar[0];
why not just
c Syntax (Toggle Plain Text)
  1. return bar;
mbd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Incompatible pointer type (double pointer in a function) Gabriel Margarido C 16 Nov 23rd, 2007 4:04 AM
Function pointer to a member function Jimbo C++ 3 May 12th, 2006 5:53 PM
Recommended Practice for returning data from function Arla C# 1 Aug 16th, 2005 1:21 PM
Returning a value from a variable to the main function colt C 3 Apr 28th, 2005 8:56 AM
Returning An Array From a Function ViZioN C++ 5 Feb 21st, 2005 7:45 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC