Thread: function return on right hand side of "="

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    44

    function return on right hand side of "="

    i recently came across a code which was like

    Code:
     func1() = 0;
    if the function returns an int, what does this code do. can we have function returning a value and be on the right hand side of "="?
    where would such code be useful?

    thanks
    sedy

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by sed_y View Post
    i recently came across a code which was like

    Code:
     func1() = 0;
    if the function returns an int, what does this code do. can we have function returning a value and be on the right hand side of "="?
    where would such code be useful?

    thanks
    sedy
    The only such situation I know about is when the function returns a value by reference(but that is in C++)

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    44
    Quote Originally Posted by manasij7479 View Post
    The only such situation I know about is when the function returns a value by reference(but that is in C++)
    hi,
    can you elaborate on that?
    sedy

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by sed_y
    can you elaborate on that?
    Before that: are you sure you saw that line of code in a C, not a C++, program?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    C++ is a different language than C. Do you actually want to know about C++, or stick with C?

  6. #6
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by laserlight View Post
    Before that: are you sure you saw that line of code in a C, not a C++, program?
    What is its meaning in a C context ?

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by manasij7479 View Post
    What is its meaning in a C context ?
    Syntax error... LValue required.

  8. #8
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by CommonTater View Post
    Syntax error... LValue required.
    Then he must've seen it in C++ code.

    @sed_y : This might be a useful read.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    It will have been a C++ pure virtual function declaration.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    Registered User
    Join Date
    May 2011
    Posts
    44
    hi all,
    It was a C++ code. but i thought,
    C might have it too. thats why i posted it.

    sedy

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The closest thing in C would be a function pointer:
    Code:
    void foo( void );
    void bar( void );
    ...
    void (*baz)( void ) = foo;
    
    baz();
    bar = bar;
    baz();
    baz = NULL;
    But there is no actual () on the assignments.


    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by iMalc
    It will have been a C++ pure virtual function declaration.
    Possible, but it would then be missing the return type.

    Quote Originally Posted by sed_y
    It was a C++ code. but i thought,
    C might have it too. thats why i posted it.
    Next time declare that this is not C, but you want to know if it is valid in C. Actually, if you wanted an explanation, it would have been better to ask for it in the C++ programming forum, with an additional question of whether it applies to C too.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "side-by-side configuration is incorrect"
    By Sharke in forum Windows Programming
    Replies: 9
    Last Post: 02-09-2010, 07:25 PM
  2. Isn't "return" supposed to exit a function?
    By cunnus88 in forum C++ Programming
    Replies: 7
    Last Post: 01-22-2008, 04:58 AM
  3. Replies: 2
    Last Post: 10-08-2005, 04:09 PM
  4. "return function" doesn't work
    By Cris987 in forum C++ Programming
    Replies: 10
    Last Post: 03-04-2004, 11:04 PM
  5. Replies: 4
    Last Post: 06-24-2003, 11:52 PM

Tags for this Thread