Re: const struct members
- From: "Rod Pemberton" <do_not_have@xxxxxxxxxxxxxxxxx>
- Date: Tue, 2 May 2006 03:30:17 -0400
"Bill Pursell" <bill.pursell@xxxxxxxxx> wrote in message
news:1146542089.926612.309830@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Rod Pemberton wrote:you
"Bill Pursell" <bill.pursell@xxxxxxxxx> wrote in message
news:1146511188.133768.226850@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Suppose I have a structure with many members, and I pass a pointer to
that structure to a function. I'd like the prototype of the function
to specify that it will only be changing certain members of the
function, but I have only the following horrific way to do that. Can
someone please suggest a better alternative?
Since modify_b can't modify 'a' and modify_a can't modify 'b', why do
corruptionneed to protect the other structure elements? Is there a data
issue here?
There's no data corruption problem, I just observed that in many
instances I have data structures with several buffers getting passed
into functions, and the only manner by which I can tell which function
modifies which buffer is to inspect the function body/comments. I
could modify the protoypes to specify that the struct is constant, but
that of course gives no assurance on the contents of foo->a. I suppose
the only other solution is to define the structure as having const
members and making it difficult to assign/modify things. Something
like:
It seems that you are trying to create C features with may be available in
C++. I know very little about C++, but IIRC, you can implement data
protection due to the object oriented feature of binding code with data.
The code gets executed for each action on the data. Which means, you can
prevent variables from being multiply assigned, set, reset or whatever...
Perhaps you might look into using a small amount of C++.
Rod Pemberton
.
- References:
- const struct members
- From: Bill Pursell
- Re: const struct members
- From: Rod Pemberton
- Re: const struct members
- From: Bill Pursell
- const struct members
- Prev by Date: Re: Setting pointers to null after freeing them
- Next by Date: Re: #iidef and #define to debug program
- Previous by thread: Re: const struct members
- Next by thread: Re: const struct members
- Index(es):
Relevant Pages
|