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