Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Return value from a funtion

Return value from a funtion

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AkashAg
    wrote on last edited by
    #1

    Hi, I want to know the side effects if I don't save the value returned from a function call. ex:

    int foo()
    {
    return (10);
    }

    main()
    {
    foo();
    }

    Doubts: 1. Does this type of code may cause some warnings or other issues? 2. Is it an optimized approach or do I need to save the value returned by foo()? Thanks for ur help. Akash

    _ S 2 Replies Last reply
    0
    • A AkashAg

      Hi, I want to know the side effects if I don't save the value returned from a function call. ex:

      int foo()
      {
      return (10);
      }

      main()
      {
      foo();
      }

      Doubts: 1. Does this type of code may cause some warnings or other issues? 2. Is it an optimized approach or do I need to save the value returned by foo()? Thanks for ur help. Akash

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Ideally, you should take the returned value because there is some reason for the returning it. Could be an error code that most people don't check. :) As for optimization, you will have one less instruction if you don't take the return value.

      «_Superman_» I love work. It gives me something to do between weekends.

      A 1 Reply Last reply
      0
      • _ _Superman_

        Ideally, you should take the returned value because there is some reason for the returning it. Could be an error code that most people don't check. :) As for optimization, you will have one less instruction if you don't take the return value.

        «_Superman_» I love work. It gives me something to do between weekends.

        A Offline
        A Offline
        AkashAg
        wrote on last edited by
        #3

        yaa, true... But if I've already checked for error conditions and all. does it matter...

        _ 1 Reply Last reply
        0
        • A AkashAg

          yaa, true... But if I've already checked for error conditions and all. does it matter...

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          It really doesn't matter. For example, I didn't know printf returned any value at all for a long time. I believe its return value is not checked 99% of the times.

          «_Superman_» I love work. It gives me something to do between weekends.

          1 Reply Last reply
          0
          • A AkashAg

            Hi, I want to know the side effects if I don't save the value returned from a function call. ex:

            int foo()
            {
            return (10);
            }

            main()
            {
            foo();
            }

            Doubts: 1. Does this type of code may cause some warnings or other issues? 2. Is it an optimized approach or do I need to save the value returned by foo()? Thanks for ur help. Akash

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            akashag wrote:

            1. Does this type of code may cause some warnings or other issues?

            Compile it and see...neither gcc nor VC++ seem to give any warnings.

            akashag wrote:

            2. Is it an optimized approach or do I need to save the value returned by foo()?

            You don't need to save the return value...but you then have to ask yourself - why am I calling the function? Doers it have other, non-visible side-effects? Obviously, this simple case doesn't, but many functions do effect some form of global data, while class methods can obviously update object instance data.

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups