Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Daniel <daniel@inventati.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Few questions about casting away const. |
| Date | 2014-03-04 11:18 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <lf4cq3$mie$1@speranza.aioe.org> (permalink) |
const char *s = "abc";
char *t = s;
printf("%s", s);
Firstly, the direct cast from 'const char *' to 'char *' which is seen on
the second line. I've read that this is illegal in standard C, is that
true?
Secondly, given that printf's 's' specifier matches a 'char *', the
comment in section 6.5.2.2p6 of C11 seems to indicate that these types
are interchangeable in this situation. If the direct cast is invalid,
would this be a legal alternative?:
#define unconst(p) (unconst_(0, p))
char *unconst_(int unused, ...)
{
va_list args;
char *r;
va_start(args, unused);
r = va_arg(args, char *);
va_end(args);
return r;
}
const char *s = "abc";
char *t = unconst(s);
Or, are there other possibilities?
Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread
Few questions about casting away const. Daniel <daniel@inventati.org> - 2014-03-04 11:18 +0000
Re: Few questions about casting away const. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-04 12:39 +0000
Re: Few questions about casting away const. Kaz Kylheku <kaz@kylheku.com> - 2014-03-04 17:05 +0000
Re: Few questions about casting away const. Keith Thompson <kst-u@mib.org> - 2014-03-04 10:16 -0800
Re: Few questions about casting away const. Daniel <daniel@inventati.org> - 2014-03-05 03:45 +0000
Re: Few questions about casting away const. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-05 04:20 +0000
Re: Few questions about casting away const. James Kuyper <jameskuyper@verizon.net> - 2014-03-04 15:18 -0500
Re: Few questions about casting away const. Daniel <daniel@inventati.org> - 2014-03-05 04:14 +0000
Re: Few questions about casting away const. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-05 04:35 +0000
Re: Few questions about casting away const. Daniel <daniel@inventati.org> - 2014-03-05 06:11 +0000
Re: Few questions about casting away const. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-05 12:14 +0000
Re: Few questions about casting away const. Daniel Harrison <daniel@inventati.org> - 2014-03-07 04:31 +0000
Re: Few questions about casting away const. Barry Schwarz <schwarzb@dqel.com> - 2014-03-06 21:23 -0800
Re: Few questions about casting away const. Kaz Kylheku <kaz@kylheku.com> - 2014-03-07 05:59 +0000
Re: Few questions about casting away const. James Kuyper <jameskuyper@verizon.net> - 2014-03-07 07:18 -0500
Re: Few questions about casting away const. Tim Rentsch <txr@alumni.caltech.edu> - 2014-03-10 00:30 -0700
Re: Few questions about casting away const. Keith Thompson <kst-u@mib.org> - 2014-03-10 09:00 -0700
Re: Few questions about casting away const. Tim Rentsch <txr@alumni.caltech.edu> - 2014-03-10 11:13 -0700
Re: Few questions about casting away const. Keith Thompson <kst-u@mib.org> - 2014-03-10 12:10 -0700
Re: Few questions about casting away const. Kaz Kylheku <kaz@kylheku.com> - 2014-03-11 07:38 +0000
Re: Few questions about casting away const. Tim Rentsch <txr@alumni.caltech.edu> - 2014-03-29 09:02 -0700
Re: Few questions about casting away const. Tim Rentsch <txr@alumni.caltech.edu> - 2014-03-10 02:29 -0700
Re: Few questions about casting away const. Keith Thompson <kst-u@mib.org> - 2014-03-10 10:52 -0700
Re: Few questions about casting away const. Tim Rentsch <txr@alumni.caltech.edu> - 2014-03-29 08:50 -0700
csiph-web