473,322 Members | 1,421 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,322 software developers and data experts.

pointers difficulties

Hello,

I have some problems with my pointers.
For exemple I have pointer as

uchar* pr;
pr = (uchar *) malloc(3 * compSize);

int i = 0;
for( i = 0 ; i< 4; i++){
uchar red = ((body[i] >> 16) & 0xff);
*pr++ = red;
}
for( i = 4 ; i > 0; i--) {
printf("pointers: %x %x %x \n", *(pr-i));
}

As you can see my problem is that I have lost the first position of my pointer,
how can I fix this situation? Supposing that I don't want to create another pointer?
thanks

Marcelo

PS: whats the difference between
*pointer
and
pointer[value]

Dec 14 '05 #1
2 1111
Marcelo wrote:
Hello,

I have some problems with my pointers.
For exemple I have pointer as

uchar* pr;
pr = (uchar *) malloc(3 * compSize);
In particular reason for using malloc in C++? That's very C. 'new' is
better.
int i = 0;
for( i = 0 ; i< 4; i++){
uchar red = ((body[i] >> 16) & 0xff);
*pr++ = red;
}
for( i = 4 ; i > 0; i--) {
printf("pointers: %x %x %x \n", *(pr-i));
}

As you can see my problem is that I have lost the first position of
my pointer,
how can I fix this situation?
Change *pr++ to pr[i] or *(pr+i).
Supposing that I don't want to create
another pointer?
Then don't, but the code might be more efficient if you do. Incrementing a
pointer is likely to be at least as simple as, and possibly simpler than,
calculating an address from an index.

thanks

Marcelo

PS: whats the difference between
*pointer
and
pointer[value]


*(pointer+i) is the equivalent of pointer[i].

DW
Dec 14 '05 #2
David White wrote:
Marcelo wrote:
Hello,

I have some problems with my pointers.
For exemple I have pointer as

uchar* pr;
pr = (uchar *) malloc(3 * compSize);


In particular reason for using malloc in C++? That's very C. 'new' is
better.


That should be 'Any particular reason'.

DW
Dec 14 '05 #3

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

Similar topics

94
by: Gabriel Zachmann | last post by:
Is it correct to say that strong/weak typing does not make a difference if one does not use any pointers (or adress-taking operator)? More concretely, I am thinking particularly of Python vs C++....
4
by: Sat | last post by:
Hi, I have a simplified version of a problem that I am facing (hope I haven't oversimplified it). This code doesn't work now and I want to find how I can make it work. Can I call the derived...
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
3
by: Peter Goddard | last post by:
Hello, Is it possible, using casting to promote... void *Ptr; To behave like... void (*FnPtr)(void); ?
15
by: Marc Thrun | last post by:
Hello, I've got a few questions: 1) Given the two structs struct A { int x; }; and
2
by: warnockg90 | last post by:
Hi. I am trying to write a program that utilises pointers to dynamically allocate memory. Initially I used arrays to run the program but this is not so good when you have user inputted values and...
20
by: Joe Van Dyk | last post by:
Is there some rule of thumb about when to use pointers to an object and when to use a reference* to an object when a class needs to have objects as data members? Example: class A { B* b_ptr;...
59
by: MotoK | last post by:
Hi Experts, I've just joined this group and want to know something: Is there something similar to smart pointers in C or something to prevent memory leakages in C programs. Regards MotoK
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.