what would be the thought to do: const void *usein = in;

G

G G

i'm not asking why they did this in the sense of the actually working program.

just for reference:

http://freshbsd.org/commit/openbsd/...f=lib/libssl/src/crypto/engine/hw_cryptodev.c

i'm asking more or less, what would be the thought that would cause the choice of doing, setting, a const void pointer.

i don't know if i'm saying this right ( writing ) but...

i need a pointer to a location in memory, that will not change, in which the type of that object/data, i'm going to point to, or in this case assign to, i'm not sure how that object/data is typed. ??

sorry about that.

rephrase: ( on the thought )
so. i have a location in memory which i will place this data.
i want this location to always be the same place.
the data being place there, i'm not sure of its type, or not sure how the system handles the type.

so i then choose:
const void *pointer_to_location_that_will_not_change = data_that_i_want_at_that_location;

would that be the thought? and could you give an example of why one would do that.

thanks,

g.
 
B

Ben Bacarisse

G G said:
i'm not asking why they did this in the sense of the actually working
program.
i'm asking more or less, what would be the thought that would cause
the choice of doing, setting, a const void pointer.

That's ambiguous: const void * and void *const and different.
i don't know if i'm saying this right ( writing ) but...

i need a pointer to a location in memory, that will not change, in
which the type of that object/data, i'm going to point to, or in this
case assign to, i'm not sure how that object/data is typed. ??

You've made the English ambiguous as well. Is it the "pointer that will
not change" (that's a void *const) or the location in memory that won't
change (that's a const void *)?
sorry about that.

rephrase: ( on the thought )
so. i have a location in memory which i will place this data.
i want this location to always be the same place.
the data being place there, i'm not sure of its type, or not
sure how the system handles the type.

so i then choose:
const void *pointer_to_location_that_will_not_change =
data_that_i_want_at_that_location;

The names you've used just add to the confusion. The best I can offer is
these two alternatives. If you want to say that the pointer won't
change you write

void *const ptr = ...;

and if you want to say that the pointed-to location won't be changed
using ptr you write:

const void *ptr = ...;

And you can, of course, do both:

const void *const ptr = ...;

<snip>
 
K

Kaz Kylheku

i'm not asking why they did this in the sense of the actually working program.

just for reference:

http://freshbsd.org/commit/openbsd/...f=lib/libssl/src/crypto/engine/hw_cryptodev.c

Did you read the commit comment? It's to make the code compile with -Werror.

This means that the goofballs were previously ignoring important warnings in the code.

Specifically, I would guess, warnings about possible use of uninitialized variables:

char *x; /* warning: x might be used uninitialized in this function */

char *x = NULL; /* warning shuts up */

Note that the commit includes changes which initialize integer variables to zero,
not only pointer variables to null.
 
K

Keith Thompson

G G said:
rephrase: ( on the thought )
so. i have a location in memory which i will place this data.
i want this location to always be the same place.
the data being place there, i'm not sure of its type, or not sure how the system handles the type.

so i then choose:
const void *pointer_to_location_that_will_not_change = data_that_i_want_at_that_location;

The initializer needs to yield the value of the pointer, not the value
of what it points to.
 
G

G G

if you want to say that the pointed-to location won't be changed
using ptr you write:
const void *ptr = ...;

Thanks Ben, my question is what make one choose to do this?
why use a void pointer?
why use use a const void pointer?

what would lead one to make this decision to use such a construct?
 
G

G G

Did you read the commit comment? It's to make the code compile with -Werror.
This means that the goofballs were previously ignoring important warningsin the code.
Specifically, I would guess, warnings about possible use of uninitializedvariables:
char *x; /* warning: x might be used uninitialized in this function */

char *x = NULL; /* warning shuts up */
Note that the commit includes changes which initialize integer variables to zero,
not only pointer variables to null.

Kaz thanks, i didn't actually look any further then the const void *usein = in;

it was just first the time i had seen that construct and i wondered what would lead one to choose to use that construct. i didn't noticed that the authors of the program had address char pointer to NULL, which i had asked about the other day. but i'm glad you are drawing my attention to it. so what i'm learning is not just theory.

i am currently reading "Understanding and Using C Pointers". i was reading C How to Program, but when i posted a question relating to an explanation given in that book a few people to exception with the book. suggesting to book is not too good. after reading some of the groups comments on constants and const, it kinda made understanding the author's explanation a little tougher, though i believe i understand his intent, when it comes to teaching beginners.

that said many in this group are great at explaining and what is really cool is they really know the specification and include that info, where to find the reference information as well.

as for the example i was listening to Security Now and they were discussingcode and a few problems that could be found in the code do mostly to accidental coding, so to speak. they reference this software program and i tried to look at the source to see if i could read what professionals had written and i came across that const void pointer. i wondered why one would choose that construct. what lead the program to need that.

again thank Kaz,

g.
 
B

Barry Schwarz

if you want to say that the pointed-to location won't be changed


Thanks Ben, my question is what make one choose to do this?
why use a void pointer?
why use use a const void pointer?

what would lead one to make this decision to use such a construct?

You use a void * when the type of object being pointed to is either
irrelevant or possibly different at different times.

You use const void * under the same conditions but with the additional
requirement that the object pointed to will not be changed.

Look at the prototype for memcpy. The function can be used to copy
the contents of any object to any other object and uses these two
constructs to convey exactly that.
 
G

G G

You use a void * when the type of object being pointed to is either
irrelevant or possibly different at different times.
You use const void * under the same conditions but with the additional
requirement that the object pointed to will not be changed.
Look at the prototype for memcpy. The function can be used to copy
the contents of any object to any other object and uses these two
constructs to convey exactly that.

ok, thanks Barry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top