Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

void * and int * addition

Name: Anonymous 2013-04-21 1:29

Hey /prog/

Question for you.

How much do I actually increment up in memory when I add 1 to a void *, and how much do I increment up in memory when I add 1 to a int *?

Name: Anonymous 2013-04-21 1:42

You can't add to a void*

When you add to an int*, the actual pointer will be incremented by the amount you added multiplied by sizeof(int). This gives it an array-like behaviour.

These two statements are the same:
x = *(myPtr + 5);
x = myPtr[5];

Name: Anonymous 2013-04-21 1:44

Actually, turned out I was wrong about void*. Adding 1 to it adds 1 to the pointer itself.

Name: Anonymous 2013-04-21 2:04

>>3
I thought that was an error? I guess not.

Name: Anonymous 2013-04-21 4:49

>>3
Thats noet what I mean. I know void *t what I mean. I know void * junk +=1 moves up a byte ( i think) how much does an int * junk+=1 move the pointer up by?

Name: Anonymous 2013-04-21 5:17

sizeof(int) >>3 said this but you must have missed the wording.

Name: Anonymous 2013-04-21 5:23

>>3
YAINT RED DA FUCKIN STANDARD

Name: Anonymous 2013-04-21 5:24

>>3
CAST IT TO A char * YA FUCKIN HIPPIE

Name: Anonymous 2013-04-21 7:03

Why use void* when we can just use 32 and 64 bit integers as generic type pointers? (I haven't read the standard)

Name: Anonymous 2013-04-21 17:48

>>3,4,7
Arithmetic on void * is not defined by the standard, but some compilers (most notably gcc) allow it anyway. In such exceptional cases a void * will behave the same as a char *.

Don't change these.
Name: Email:
Entire Thread Thread List