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. Long pointer to character C++

Long pointer to character C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++xmltutorialquestion
9 Posts 6 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
    pix_programmer
    wrote on last edited by
    #1

    Is it possible in C++ to declare a pointer as long?( like long int). I'm reading some string from a XML file and assigning it to a const char* variable. But the application crashes, when string is huge. Is there any maximum limit for char * variable? How to avoid the crash,when the string is huge?

    D L S CPalliniC A 6 Replies Last reply
    0
    • P pix_programmer

      Is it possible in C++ to declare a pointer as long?( like long int). I'm reading some string from a XML file and assigning it to a const char* variable. But the application crashes, when string is huge. Is there any maximum limit for char * variable? How to avoid the crash,when the string is huge?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      pix_programmer wrote:

      Is it possible in C++ to declare a pointer as long?( like long int).

      On most platforms, both are 32-bit so there would be no difference.

      pix_programmer wrote:

      Is there any maximum limit for char * variable?

      A pointer just points to something.

      pix_programmer wrote:

      How to avoid the crash,when the string is huge?

      Showing the relevant code, for starters.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

      1 Reply Last reply
      0
      • P pix_programmer

        Is it possible in C++ to declare a pointer as long?( like long int). I'm reading some string from a XML file and assigning it to a const char* variable. But the application crashes, when string is huge. Is there any maximum limit for char * variable? How to avoid the crash,when the string is huge?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        A pointer is a pointer is a pointer; it is a fixed size and has nothing to do with the length of the item(s) that it is pointing to. You need to use your debugger to investigate why your program is crashing.

        One of these days I'm going to think of a really clever signature.

        1 Reply Last reply
        0
        • P pix_programmer

          Is it possible in C++ to declare a pointer as long?( like long int). I'm reading some string from a XML file and assigning it to a const char* variable. But the application crashes, when string is huge. Is there any maximum limit for char * variable? How to avoid the crash,when the string is huge?

          S Offline
          S Offline
          Stefan_Lang
          wrote on last edited by
          #4

          pix_programmer wrote:

          I'm reading some string from a XML file and assigning it to a <code>const char*</code> variable.

          That doesn't make sense. A pointer can only be sensibly initialized within the program, at runtime, because only then does the computer know where in memeory every object lies. Therefore it doesn't make sense to either store or restore a pointer to/from a file! What you need to do instead is: 1. read that string from your file 2. Allocate a char array on the heap that is big enough to contain that string (including the terminating NULL character!) 3. Assign that array to your pointer 4. Store the string in that char array. Of course, if you use std::string, that would save you some of that efort.

          D 1 Reply Last reply
          0
          • P pix_programmer

            Is it possible in C++ to declare a pointer as long?( like long int). I'm reading some string from a XML file and assigning it to a const char* variable. But the application crashes, when string is huge. Is there any maximum limit for char * variable? How to avoid the crash,when the string is huge?

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

            Application crash has nothing to do with the size of the pointer. You should show us the relevant code to get better help.

            Veni, vidi, vici.

            In testa che avete, signor di Ceprano?

            1 Reply Last reply
            0
            • S Stefan_Lang

              pix_programmer wrote:

              I'm reading some string from a XML file and assigning it to a <code>const char*</code> variable.

              That doesn't make sense. A pointer can only be sensibly initialized within the program, at runtime, because only then does the computer know where in memeory every object lies. Therefore it doesn't make sense to either store or restore a pointer to/from a file! What you need to do instead is: 1. read that string from your file 2. Allocate a char array on the heap that is big enough to contain that string (including the terminating NULL character!) 3. Assign that array to your pointer 4. Store the string in that char array. Of course, if you use std::string, that would save you some of that efort.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Stefan_Lang wrote:

              Therefore it doesn't make sense to either store or restore a pointer to/from a file!

              I think the "it" the OP was referring to was the string, not the file.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

              S 1 Reply Last reply
              0
              • D David Crow

                Stefan_Lang wrote:

                Therefore it doesn't make sense to either store or restore a pointer to/from a file!

                I think the "it" the OP was referring to was the string, not the file.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                S Offline
                S Offline
                Stefan_Lang
                wrote on last edited by
                #7

                I'm not so sure - he (or she) asked about using a bigger pointer type after all. In any case, I've found that it's often better to take a question literally - if it isn't meant that way, it helps the author to improve on it and provide a better description of the actual problem.

                1 Reply Last reply
                0
                • P pix_programmer

                  Is it possible in C++ to declare a pointer as long?( like long int). I'm reading some string from a XML file and assigning it to a const char* variable. But the application crashes, when string is huge. Is there any maximum limit for char * variable? How to avoid the crash,when the string is huge?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  A pointer is just a pointer, just pointing to something. I think your application is crashing with some other reason. just debug the code and ensure what is the problem.. if you are using visual c++ just using LPCTSTR variable for storing string data read from xml.

                  1 Reply Last reply
                  0
                  • P pix_programmer

                    Is it possible in C++ to declare a pointer as long?( like long int). I'm reading some string from a XML file and assigning it to a const char* variable. But the application crashes, when string is huge. Is there any maximum limit for char * variable? How to avoid the crash,when the string is huge?

                    A Offline
                    A Offline
                    April Fans
                    wrote on last edited by
                    #9

                    Hello there, In computer science, a pointer is a programming language data type whose value is directly linked to another - by means of pointing to the value that is stored elsewhere in the computer memory using its address. The basic syntax is define a pointer is as follows: int *ptr Now, because a pointer points to a memory location - I don't believe that it can be define as long. With Kind Regards, Live Support Software for Business

                    April Comm100 - Leading Live Chat Software Provider

                    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