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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is there any standard for returning values from a function?

Is there any standard for returning values from a function?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 Posts 5 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.
  • M Offline
    M Offline
    Mushtaque Nizamani
    wrote on last edited by
    #1

    Hi, Is there any standard for return values from a function, for example if my function returns only two value(true/false) then i would like to assign bool as its return value, but if i have got three values(0,1,2), then what data type should be the used as return value.

    Best Regards, Mushq Mushtaque Ahmed Nizamani Software Engineer Ultimus Pakistan "English is my second language, so please don't mind if i do some grammatical or spelling mistakes in my messages."

    T CPalliniC K 3 Replies Last reply
    0
    • M Mushtaque Nizamani

      Hi, Is there any standard for return values from a function, for example if my function returns only two value(true/false) then i would like to assign bool as its return value, but if i have got three values(0,1,2), then what data type should be the used as return value.

      Best Regards, Mushq Mushtaque Ahmed Nizamani Software Engineer Ultimus Pakistan "English is my second language, so please don't mind if i do some grammatical or spelling mistakes in my messages."

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      you have plenty of types. if the function may return little integers, char is good enough. but short, int, long are possible choices.


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      1 Reply Last reply
      0
      • M Mushtaque Nizamani

        Hi, Is there any standard for return values from a function, for example if my function returns only two value(true/false) then i would like to assign bool as its return value, but if i have got three values(0,1,2), then what data type should be the used as return value.

        Best Regards, Mushq Mushtaque Ahmed Nizamani Software Engineer Ultimus Pakistan "English is my second language, so please don't mind if i do some grammatical or spelling mistakes in my messages."

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        If the function may return only a small set of integers (such as {0,1,2}) then the enum type is a good choiche. Usually you can assign to each member of the set a meanigful name:

        enum TrustLevel
        {
        LOW = 0,
        AVERAGE,
        HIGH
        };

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • M Mushtaque Nizamani

          Hi, Is there any standard for return values from a function, for example if my function returns only two value(true/false) then i would like to assign bool as its return value, but if i have got three values(0,1,2), then what data type should be the used as return value.

          Best Regards, Mushq Mushtaque Ahmed Nizamani Software Engineer Ultimus Pakistan "English is my second language, so please don't mind if i do some grammatical or spelling mistakes in my messages."

          K Offline
          K Offline
          Kenan Aksoy
          wrote on last edited by
          #4

          return int . so you can return up to 2 billion. :laugh:

          dlfkgj lsdfkglfkgjlfgl jldfk fldkk jk

          M CPalliniC 2 Replies Last reply
          0
          • K Kenan Aksoy

            return int . so you can return up to 2 billion. :laugh:

            dlfkgj lsdfkglfkgjlfgl jldfk fldkk jk

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Kenan Aksoy wrote:

            2 billion

            That's all? What if you need more in the future? You have to think ahead, you know. :rolleyes:

            Mark Salsbery Microsoft MVP - Visual C++ "Go that way, really fast. If something gets in your way, turn."

            1 Reply Last reply
            0
            • K Kenan Aksoy

              return int . so you can return up to 2 billion. :laugh:

              dlfkgj lsdfkglfkgjlfgl jldfk fldkk jk

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              Actually 4 billions :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              In testa che avete, signor di Ceprano?

              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