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. Managed C++/CLI
  4. Why does integer work and not boolean

Why does integer work and not boolean

Scheduled Pinned Locked Moved Managed C++/CLI
question
3 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.
  • 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

    M A 2 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

      M Offline
      M Offline
      Matt Godbolt
      wrote on last edited by
      #2

      A very strange bug; sounds to me like some kind of memory access splat. There's not too much to go on from your example, but the fact you're using an array (ptrs[]) and that changing the size of the class (by changing bool to int [see note]) causes a crash, sounds to me like something somewhere isn't accessing the right memory. Ensure you've allocated enough memory for ptrs[] and that 'pos' is in within a valid range - if that doesn' solve it perhaps post a bit more information - whereabouts is the crash? I assume it's on the 'p->ptrs[pos]->isLeaf' line. Matt Godbolt Engineer, ProFactor Software StyleManager project

      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

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

        mmmm, huffman

        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