By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Assign to const pointer in C

P: n/a
In an older version of gcc, I could cast away const.
When porting to gcc 4.1.2, the compiler complains.
Expand|Select|Wrap|Line Numbers
  1. char * const buffer;
  2. ...
  3.    (char*)buffer = malloc(SIZE);
  4.  
In C++, there is a const_cast<>, but how should this be done in C?
Nov 8 '10 #1
Share this Question
Share on Google+
2 Replies


Markus
Expert 5K+
P: 6,050
Well, does that make sense to you? You define the variable as a constant, meaning it is immutable (cannot be changed). If you're wanting to modify the data of this constant, instead define it without 'const'. Makes sense to me.
Nov 8 '10 #2

Expert 100+
P: 2,396
Is the gcc complaint a warning or an error? My recollection is that it is a warning. If so, then you don't have to change anything -- just live with it.
Nov 8 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.