473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

unsigned char* compiler error

I am getting a exception error when I complie my code.

The error is:

- imageData 0x00000000 <Bad Ptr>

type unsigned char *

I think it is from when I declare some of my char variables

unsigned char *imageData; // the map image data

unsigned char *landTexture; // land texture data

unsigned char *waterTexture; // water texture data

I have tried changing the data type but I just get cannot convert
errors. Any help would be appreciated.

Nov 1 '06 #1
5 2823
ry********@hotmail.com wrote:
I am getting a exception error when I complie my code.
When you compile it, or when you run it?
>
The error is:

- imageData 0x00000000 <Bad Ptr>

type unsigned char *

I think it is from when I declare some of my char variables

unsigned char *imageData; // the map image data

unsigned char *landTexture; // land texture data

unsigned char *waterTexture; // water texture data

I have tried changing the data type but I just get cannot convert
errors. Any help would be appreciated.
Not enough information. Show some code that exhibits the problem.
Nov 1 '06 #2
<ry********@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
>I am getting a exception error when I complie my code.

The error is:

- imageData 0x00000000 <Bad Ptr>

type unsigned char *

I think it is from when I declare some of my char variables

unsigned char *imageData; // the map image data

unsigned char *landTexture; // land texture data

unsigned char *waterTexture; // water texture data

I have tried changing the data type but I just get cannot convert
errors. Any help would be appreciated.
That is a null pointer error. I doubt you are getting an error when you
compile your code, but when you run it, since that is a run time error.

Basically, it means that your pointer isn't pointing to anything. Most
likely you are running in debug mode which was nice enough to initialize the
variable to NULL for you, but in run time it wouldn't, then it would be a
different type of memory error.

unsigned char *imageData = NULL;

Now try to do something wiht imageData and you'll get a memory error,
because it's not pointing to anything. Okay, you have a pointer to unsigned
char. What do you want to do with it? Do you want to point it to an
already allocated buffer of image data? Or do you want to allocate memory
to hold image data?

The pointer itself is just something that will point to unsigned char data.
But you still have to tell it to point there.
I.E.

unsigned char* imageData = NULL;
imageData = new unsigned char[1000];
Now imeageData points to a block of 1000 unsigned chars that were allocated
using new. The memory is uninitialized and can, and will, contain anything.
You ned to set the data to something using the pointer.
imageData[0] = 'X';
yada yada. However you want to do it. Remmeber, when you are done with the
memory to free it.
free[] imageData;
imageData = NULL; // Some suggest dong this, some don't.

Another way, is to make your unsigned char ponter point to some buffer
somewhere.

unsigned char* imageData = NULL;
imageData = &SomeBuffer;

now imageData will point to the location that SomeBuffer is stored (which
needs to be unsigned char without a cast).
Since you didn't use new to allocate the data, don't use free to release it
(not for imageData anyway).

Incidently, most of this code can be put on one line.
unsigned char* imageData = new unsigned char[1000];
unsigned char* imageData = &SomeBuffer;

It seems that you are creating a pointer and are not sure what to do with
it, I think you need to study up on pointers a bit more.
Nov 1 '06 #3

Jim Langston wrote in message ...
><ry********@hotmail.comwrote in message
>>

unsigned char* imageData = NULL;
imageData = new unsigned char[1000];
>imageData[0] = 'X';
yada yada. However you want to do it. Remmeber, when you are done with the
memory to free it.
// >free[] imageData;
delete[] imageData;
>imageData = NULL; // Some suggest dong this, some don't.
--
Bob R
POVrookie
Nov 1 '06 #4

Jim Langston wrote:
<ry********@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
I am getting a exception error when I complie my code.

The error is:

- imageData 0x00000000 <Bad Ptr>

type unsigned char *

I think it is from when I declare some of my char variables

unsigned char *imageData; // the map image data

unsigned char *landTexture; // land texture data

unsigned char *waterTexture; // water texture data

I have tried changing the data type but I just get cannot convert
errors. Any help would be appreciated.

That is a null pointer error. I doubt you are getting an error when you
compile your code, but when you run it, since that is a run time error.

Basically, it means that your pointer isn't pointing to anything. Most
likely you are running in debug mode which was nice enough to initialize the
variable to NULL for you, but in run time it wouldn't, then it would be a
different type of memory error.

unsigned char *imageData = NULL;

Now try to do something wiht imageData and you'll get a memory error,
because it's not pointing to anything. Okay, you have a pointer to unsigned
char. What do you want to do with it? Do you want to point it to an
already allocated buffer of image data? Or do you want to allocate memory
to hold image data?

The pointer itself is just something that will point to unsigned char data.
But you still have to tell it to point there.
I.E.

unsigned char* imageData = NULL;
imageData = new unsigned char[1000];
Now imeageData points to a block of 1000 unsigned chars that were allocated
using new. The memory is uninitialized and can, and will, contain anything.
You ned to set the data to something using the pointer.
imageData[0] = 'X';
yada yada. However you want to do it. Remmeber, when you are done with the
memory to free it.
free[] imageData;
imageData = NULL; // Some suggest dong this, some don't.

Another way, is to make your unsigned char ponter point to some buffer
somewhere.

unsigned char* imageData = NULL;
imageData = &SomeBuffer;

now imageData will point to the location that SomeBuffer is stored (which
needs to be unsigned char without a cast).
Since you didn't use new to allocate the data, don't use free to release it
(not for imageData anyway).

Incidently, most of this code can be put on one line.
unsigned char* imageData = new unsigned char[1000];
unsigned char* imageData = &SomeBuffer;

It seems that you are creating a pointer and are not sure what to do with
it, I think you need to study up on pointers a bit more.

Thanks for the help I figured it out. I just changed the way I pointed
to ImageData.

Nov 1 '06 #5

"BobR" <Re***********@worldnet.att.netwrote in message
news:uh*****************@bgtnsc05-news.ops.worldnet.att.net...
>
Jim Langston wrote in message ...
>><ry********@hotmail.comwrote in message
>>>

unsigned char* imageData = NULL;
imageData = new unsigned char[1000];
>>imageData[0] = 'X';
yada yada. However you want to do it. Remmeber, when you are done with
the
memory to free it.

// >free[] imageData;
delete[] imageData;
>>imageData = NULL; // Some suggest dong this, some don't.
Gah, thanks, I can't believe I did that :D
Nov 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

96
by: John Harrison | last post by:
I knew that unsigned integral data types were the cause of scads of mostly spurious warning messages, but I didn't realise that they were a security risk too (see here...
3
by: Sensei | last post by:
Hi. I have a problem with a C++ code I can't resolve, or better, I can't see what the problem should be! Here's an excerpt of the incriminated code: === bspalgo.cpp // THAT'S THE BAD...
10
by: Lars Tackmann | last post by:
Does the c standard state that for all c99 implementation char as standard is equal unsigned char ??? - or do i have to take this into account when writing my program ???.
3
by: QQ | last post by:
Hello, Here is my simple program int main() { unsigned char a =0x81; char b = 0x81; printf("unsigned char = 0x%x(%d), char = 0x%x(%d)\n",a,a,b,b); printf("cast char to unsigned...
10
by: kar1107 | last post by:
Hi all, Can the compiler chose the type of an enum to be signed or unsigned int? I thought it must be int; looks like it changes based on the assigned values. Below if I don't initialize...
6
by: Bobrick | last post by:
Hi. Thanks to everyone who replied to my last post, it turns out it wasn't the line where I was trying to treat the variable in question as an array which was the problem, but the line above. ...
26
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
i wrote: ----------------------------------------------------------------------- ---------------------------------------- unsigned char * p = reinterpret_cast<unsigned char *>("abcdg");...
14
by: moumita | last post by:
Hi All, I need to convert 4 bytes to an unsigned long. Suppose I have one array like unsigned char buf.I need to convert these 4 bytes into a single unsigned long. Is the following piece of code...
29
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.