Re: [Dev-C++] Const member in a Struct
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jonathan W. <jon...@gm...> - 2007-07-26 07:56:12
|
Hi,
You can declare an instance of this struct like this :
struct check foo = {42};
If you are mallocing your instances, I'm not sure you can set this value
legally
This _should_ work though
>> Hack <<
struct check *foo;
//malloc, checks, etc
*(int *)foo = 42;
>> Hack <<
A safer version would be (still a bit evil though):
struct check {
const int variable;
};
struct check_rw {
int variable;
};
struct check *foo;
//malloc, checks, etc
((struct check_rw *)foo).variable = 42;
I may be overlooking an option, though.
Regards,
Jonathan
On 7/26/07, Muhammad Ammar <amm...@ho...> wrote:
>
> Hope everyone is in good health.
>
> if have a structure like the following
>
> struct check
> {
> const int variable;
> };
>
> than, how to initialize the data member "variable".
>
>
> Best Regards
>
> Muhammad Ammar
>
> _________________________________________________________________
> http://im.live.com/messenger/im/home/?source=hmtextlinkjuly07
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
--
<Morpheus> linux, c'est une question de VI ou de MORE
|