Like Tree2Likes
  • 1 Post By manasij7479
  • 1 Post By iMalc

function return on right hand side of "="

This is a discussion on function return on right hand side of "=" within the C Programming forums, part of the General Programming Boards category; i recently came across a code which was like Code: func1() = 0; if the function returns an int, what ...

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,528
    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++)
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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
    22,274
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,185
    C++ is a different language than C. Do you actually want to know about C++, or stick with C?

  6. #6
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,528
    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 ?
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,528
    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.
    sed_y likes this.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    It will have been a C++ pure virtual function declaration.
    sed_y likes this.
    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
    22,274
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 05: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-25-2003, 12:52 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21