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. Syntax Question

Syntax Question

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 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.
  • P Offline
    P Offline
    pgav
    wrote on last edited by
    #1

    Looking at this syntax, I can't quite see what the end result should be. What does this function return? long comm_fm_node_id(comm_fm_dev_t *dev, long group) { return (group == 0) ? MCAST_nodeid : -1; } Patrick

    J T Z 3 Replies Last reply
    0
    • P pgav

      Looking at this syntax, I can't quite see what the end result should be. What does this function return? long comm_fm_node_id(comm_fm_dev_t *dev, long group) { return (group == 0) ? MCAST_nodeid : -1; } Patrick

      J Offline
      J Offline
      Justin Tay
      wrote on last edited by
      #2

      if(group == 0) return MCAST_nodeid; else return -1;

      1 Reply Last reply
      0
      • P pgav

        Looking at this syntax, I can't quite see what the end result should be. What does this function return? long comm_fm_node_id(comm_fm_dev_t *dev, long group) { return (group == 0) ? MCAST_nodeid : -1; } Patrick

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

        it means :

        long comm_fm_node_id(comm_fm_dev_t *dev, long group) {
        if (group == 0) {
        return MCAST_nodeid;
        }
        else {
        return -1;
        }
        }

        but i really don't see what dev is passed to the function if it doesn't use it, and i suspect MCAST_nodeid to be a global variable...


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        P 1 Reply Last reply
        0
        • T toxcct

          it means :

          long comm_fm_node_id(comm_fm_dev_t *dev, long group) {
          if (group == 0) {
          return MCAST_nodeid;
          }
          else {
          return -1;
          }
          }

          but i really don't see what dev is passed to the function if it doesn't use it, and i suspect MCAST_nodeid to be a global variable...


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          P Offline
          P Offline
          pgav
          wrote on last edited by
          #4

          Dev isn't used because it's only a partial implementation... I'm trying to finish the implementation... :) Thanks for your help. Patrick

          1 Reply Last reply
          0
          • P pgav

            Looking at this syntax, I can't quite see what the end result should be. What does this function return? long comm_fm_node_id(comm_fm_dev_t *dev, long group) { return (group == 0) ? MCAST_nodeid : -1; } Patrick

            Z Offline
            Z Offline
            Zac Howland
            wrote on last edited by
            #5

            pgav wrote:

            long comm_fm_node_id(comm_fm_dev_t *dev, long group) { return (group == 0) ? MCAST_nodeid : -1; }

            By the way, be VERY judicious when using the ternary operator (which is what the expression ? result_if_true : result_if_false is called). Most of the time, it is far more clear to write:

            if (expression)
            {
            	return SomeValue;
            }
            else
            {
            	return SomeOtherValue;
            }
            

            I can't tell you how many bugs I've run into because people tried to get fancy with the ternary operator and do things like:

            return expression1 ? expression2 ? expression4 ? 1 : 0 : 3 : expression3 ? 2 : 4;
            

            If you run into something like that, you should hunt down the person who wrote it, take them out behind your office, and ... well, you get the idea. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

            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