Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Error allocating memory
Forum Update on Monday, May 27th 2025

Error allocating memory

Scheduled Pinned Locked Moved Solved C++ Gurus
4 Posts 3 Posters 627 Views
  • 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.
  • J Offline
    J Offline
    jenya7
    wrote on last edited by
    #1
    int xc_init()
    {
        #define int intptr_t;
        
        int poolsize;                 // default size of text/data/stack
        int *text,    
        
        poolsize = 1 * 1024;
        
        if (!(text = malloc(poolsize)))  //error: assigning to 'intptr_t *' (aka 'int *') from incompatible type 'void *'
            return -1;
        
        
    }
    

    here on malloc I get - error: assigning to 'intptr_t *' (aka 'int *') from incompatible type

    jsulmJ 1 Reply Last reply
    0
    • J jenya7
      int xc_init()
      {
          #define int intptr_t;
          
          int poolsize;                 // default size of text/data/stack
          int *text,    
          
          poolsize = 1 * 1024;
          
          if (!(text = malloc(poolsize)))  //error: assigning to 'intptr_t *' (aka 'int *') from incompatible type 'void *'
              return -1;
          
          
      }
      

      here on malloc I get - error: assigning to 'intptr_t *' (aka 'int *') from incompatible type

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @jenya7 Basic C/C++: malloc() returns void*, so cast it to int*

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      2
      • jsulmJ jsulm

        @jenya7 Basic C/C++: malloc() returns void*, so cast it to int*

        J Offline
        J Offline
        jenya7
        wrote on last edited by
        #3

        @jsulm said in Error allocating memory:

        @jenya7 Basic C/C++: malloc() returns void*, so cast it to int*

        I see. Thank you.

        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          and you shouldn't use malloc() in c++ anyways.

          const size_t intCount = 1000U;
          int* intPtr = new int[intCount];
          .
          .
          .
          delete [] intPtr;

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved