Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #41366

Re: Few questions about casting away const.

From Daniel <daniel@inventati.org>
Newsgroups comp.lang.c
Subject Re: Few questions about casting away const.
Date 2014-03-05 04:14 +0000
Organization Aioe.org NNTP Server
Message-ID <lf68bs$l2s$1@speranza.aioe.org> (permalink)
References <lf4cq3$mie$1@speranza.aioe.org> <53163527.2090509@verizon.net>

Show all headers | View raw


> Everything it says in 6.5.2.2p6 is conditioned by the first sentence:
> "If the expression that denotes the called function has a type that does
> not include a prototype, ...".

I didn't notice that.

> but even if 6.5.2.2p6 were applicable, I don't seen how you reached the
> conclusion that it says that char* and const char* should be
> interchangeable.

I thought the following point would be relevant to this situation. But 
evidently it's not, due to the condition you noted earlier.

	If the function is defined with a type that does not include
	prototype, and the types of the arguments after promotion are not
	compatible with those of the parameters after promotion, the
	behavior is undefined, except for the following cases:

        ...

        -- both types are pointers to qualified or unqualified versions
	of a character type or void.

> All you've done is turned off the mandatory diagnostic. Since const
> char* is not compatible with char*, calling unconst(s) results in an
> invocation of va_arg() that gives your program undefined behavior
> (7.16.1.1p2).

This presents an interesting issue. Since printf will have to match 
either a 'char *' or a 'const char *' and the types are, as you've said, 
incompatible, would it mean that one of the following calls to printf 
exhibits undefined behaviour?

	#include <stdio.h>
	
	int main(void)
	{
		const char *s = "abc";
		char *t = "def";
	
		printf("%s\n", s);
		printf("%s\n", t);
	}

Since one can find both forms in common use, I would hope that this were 
not so.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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