okay, im going to quit pretending i know everything for a moment.someone please explain to me wtf is a "const void * const" ??
unsigned short myFunction ( const void * const start_address, size_t size );
2/25/2008 3:41:21 PM
A constant pointer to a constant void. In other words, you can't change the contents of *start_address. You also can't change what start_address points to.So both of these would be illegal:*start_address = 0x12345678;start_address = &someOtherVariable
2/25/2008 3:50:26 PM
dont you work for microsoft??
2/25/2008 5:23:18 PM
^ no it was a contract position. i quit it and got a real job. regardless, i never had to deal with const void * const type declarations in spam analysis. most of the stuff i did there was Perl anyhow.^^ i still dont get it. that last const is f'ing me up. break it down nice and slow, so's an EE can understand. [Edited on February 25, 2008 at 6:30 PM. Reason : ]
2/25/2008 6:10:02 PM
when dealing with const pointers in C++ read the declaration backwardsso what you have is a const pointer to a const voidBasically it means that you can't change the address of the pointer (ie no pointer math)And you can't dereference the pointer and call a non-const method.Oftentimes void* is used for a function pointer
2/25/2008 7:08:04 PM
2/25/2008 8:09:58 PM
The best thing to do is avoid const altogether. Also, avoid delete/dealloc and use only global variables.
2/25/2008 8:15:16 PM
i though you were serious until you said
2/25/2008 8:21:16 PM
I guess memory leaks aren't a problem for you
2/25/2008 8:24:03 PM
i agree malloc/dealloc are dangerous.but you want me to "use only global variables"
2/25/2008 8:28:36 PM
const is your friend and you should use it whenever you can. It lets the compiler prevent the user from messing with stuff that they shouldn't be able to mess with.So in this case, you are passing a reference to something to this function, but the writer of myFunction has made sure that you won't attempt any pointer math with start_address and that you won't attempt to modify whatever it points to.
2/25/2008 9:16:04 PM