User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » C variable declaration ... help Page [1]  
JoeSchmoe
All American
1219 Posts
user info
edit post

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

Andrew
New Recruit
27 Posts
user info
edit post

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

scud
All American
10804 Posts
user info
edit post

dont you work for microsoft??

2/25/2008 5:23:18 PM

JoeSchmoe
All American
1219 Posts
user info
edit post

^ 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

scud
All American
10804 Posts
user info
edit post

when dealing with const pointers in C++ read the declaration backwards

so what you have is a const pointer to a const void

Basically 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

JoeSchmoe
All American
1219 Posts
user info
edit post

Quote :
"dealing with const pointers in C++ read the declaration backwards"



oh, yeah ... CSC 114. its coming back to me. faintly...


2/25/2008 8:09:58 PM

skokiaan
All American
26447 Posts
user info
edit post

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

JoeSchmoe
All American
1219 Posts
user info
edit post

i though you were serious until you said

Quote :
"use only global variables."

2/25/2008 8:21:16 PM

skokiaan
All American
26447 Posts
user info
edit post

I guess memory leaks aren't a problem for you

2/25/2008 8:24:03 PM

JoeSchmoe
All American
1219 Posts
user info
edit post

i agree malloc/dealloc are dangerous.

but you want me to "use only global variables"

2/25/2008 8:28:36 PM

synchrony7
All American
4462 Posts
user info
edit post

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

 Message Boards » Tech Talk » C variable declaration ... help Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.