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. Why does Integer work, but not Boolean in Linux?

Why does Integer work, but not Boolean in Linux?

Scheduled Pinned Locked Moved C / C++ / MFC
questionlinux
5 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.
  • L Offline
    L Offline
    LiquidE_SA
    wrote on last edited by
    #1

    Can anyone please tell me why this code code gives a segmentation? The class NonLeafTrieNode { public: NonLeafTrieNode(){}; NonLeafTrieNode(char); private: friend class Trie; NonLeafTrieNode **ptrs; char *letters; int endOfWord; bool isLeaf; }; The code below are in the Trie class and I use this to access the isLeaf variable in the class. int flag = p->ptrs[pos]->isLeaf; if (!(pos == -1) && flag) If I keep the isLeaf variable a boolean the code gives a segmentation fault, but whenever I make it a integer the code works perfectly. Can anyone tell me why this happens. Thanks a lot LiquidE_SA

    G PJ ArendsP J P 4 Replies Last reply
    0
    • L LiquidE_SA

      Can anyone please tell me why this code code gives a segmentation? The class NonLeafTrieNode { public: NonLeafTrieNode(){}; NonLeafTrieNode(char); private: friend class Trie; NonLeafTrieNode **ptrs; char *letters; int endOfWord; bool isLeaf; }; The code below are in the Trie class and I use this to access the isLeaf variable in the class. int flag = p->ptrs[pos]->isLeaf; if (!(pos == -1) && flag) If I keep the isLeaf variable a boolean the code gives a segmentation fault, but whenever I make it a integer the code works perfectly. Can anyone tell me why this happens. Thanks a lot LiquidE_SA

      G Offline
      G Offline
      Graham Bradshaw
      wrote on last edited by
      #2

      The implication from your code is that -1 is a possible value for pos. In that case, p->ptrs[pos] is never going to work...

      1 Reply Last reply
      0
      • L LiquidE_SA

        Can anyone please tell me why this code code gives a segmentation? The class NonLeafTrieNode { public: NonLeafTrieNode(){}; NonLeafTrieNode(char); private: friend class Trie; NonLeafTrieNode **ptrs; char *letters; int endOfWord; bool isLeaf; }; The code below are in the Trie class and I use this to access the isLeaf variable in the class. int flag = p->ptrs[pos]->isLeaf; if (!(pos == -1) && flag) If I keep the isLeaf variable a boolean the code gives a segmentation fault, but whenever I make it a integer the code works perfectly. Can anyone tell me why this happens. Thanks a lot LiquidE_SA

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        LiquidE_SA wrote: int flag = p->ptrs[pos]->isLeaf; flag is an int and you are trying to assign a bool to it. When you change isLeaf to an int the types are the same.


        "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

        Within you lies the power for good; Use it!

        1 Reply Last reply
        0
        • L LiquidE_SA

          Can anyone please tell me why this code code gives a segmentation? The class NonLeafTrieNode { public: NonLeafTrieNode(){}; NonLeafTrieNode(char); private: friend class Trie; NonLeafTrieNode **ptrs; char *letters; int endOfWord; bool isLeaf; }; The code below are in the Trie class and I use this to access the isLeaf variable in the class. int flag = p->ptrs[pos]->isLeaf; if (!(pos == -1) && flag) If I keep the isLeaf variable a boolean the code gives a segmentation fault, but whenever I make it a integer the code works perfectly. Can anyone tell me why this happens. Thanks a lot LiquidE_SA

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          bool != int -- Look straight into the light!

          1 Reply Last reply
          0
          • L LiquidE_SA

            Can anyone please tell me why this code code gives a segmentation? The class NonLeafTrieNode { public: NonLeafTrieNode(){}; NonLeafTrieNode(char); private: friend class Trie; NonLeafTrieNode **ptrs; char *letters; int endOfWord; bool isLeaf; }; The code below are in the Trie class and I use this to access the isLeaf variable in the class. int flag = p->ptrs[pos]->isLeaf; if (!(pos == -1) && flag) If I keep the isLeaf variable a boolean the code gives a segmentation fault, but whenever I make it a integer the code works perfectly. Can anyone tell me why this happens. Thanks a lot LiquidE_SA

            P Offline
            P Offline
            Prakash Nadar
            wrote on last edited by
            #5

            LiquidE_SA wrote: int flag = p->ptrs[pos]->isLeaf; change it to bool flag = p->ptrs[pos]->isLeaf;


            -prakash

            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