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

Pages: 1-

void pointers

Name: Anonymous 2010-10-19 17:04

Fucking void pointers, how do they work

is it possible to deallocate a pointer casted void to an array consisting of anything besides primitive types, aka objects allocated on the heap?

ex:
Obj *array = new Obj[5];
void *cocks = (void *) array;

free(cocks);
or
Array *morecocks = (Array*)cocks;
delete [] morecocks;

on the same note, what is wrong with this code, dont say bad style i'll fucking kill you, that's not the point of it
dumbed down version:

size_t Size = 2;
Balls<int> *atest = new Balls<int>[Size];
void *vtest = (void *)atest;
ASS( vtest, sizeof(Balls<int>), Size, 5 );
delete [] atest;
atest = (Balls<int> *)vtest;

ASS does a manual realloc and index copy with last arg as new size (tested), and Balls has an <int> array and some other member variables

    for( int counter = 0; counter < 2*sizeof(Balls<int>); ++counter )
        std::cout << int(((char*)((void*)atest))[counter]) << ' ';
 returns the same values before and after (on the stack), but any atest.array[anything] now returns garbage

Name: Anonymous 2010-10-19 17:17

How juvenile.

Name: Anonymous 2010-10-19 17:24

code has terrible style

Name: Anonymous 2010-10-19 17:26

If you're not malloc-ing it, don't free it. In fact, don't malloc ever, because you're using Sepples and shit could confuse you if you're using more than one method of memory management.

Name: Anonymous 2010-10-19 17:38

No matter what your compiler does, the standard says that, while you can cast any pointer (not function pointer) to a void pointer, you can not do anything with it except cast it back to a pointer of the original type.

Name: Anonymous 2010-10-19 18:32

>>5
Only if you want it to still mean anything.

Name: Anonymous 2010-10-19 19:06

>>6
Shut up.

Name: Anonymous 2010-10-19 19:14

>>7
Hax my anus.

Name: Anonymous 2010-10-19 19:45

>>5
Fuck your shit.

-fno-strict-aliasing

Name: Anonymous 2010-10-19 19:54

>>9
That's not what that does.

Name: Anonymous 2010-10-19 20:03

>>10
Prove it.

Name: Anonymous 2010-10-20 6:17

>>11
Disprove it.

Name: Anonymous 2010-10-20 6:44

>>12
I asked first.

Name: Anonymous 2010-10-20 12:15

What's with the C/C++ related threads as of late? Wasn't this a Lisp board?

Name: Anonymous 2010-10-20 13:39

>>14
C/C++
IHBT

Name: Anonymous 2010-10-20 16:29

>>15
He meant C++/Java.

Name: Anonymous 2010-10-20 21:00

DON'T REPLY

Name: Anonymous 2011-02-03 3:05

Name: Anonymous 2012-03-28 2:16

my farts burn my anus
it hurts
in a good way

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