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


Groups > comp.lang.c > #21876

Re: interpret this code?

From Nick Bowler <nbowler@draconx.ca>
Newsgroups comp.lang.c
Subject Re: interpret this code?
Date 2012-06-05 15:55 +0000
Organization A noiseless patient Spider
Message-ID <jqla67$2rm$1@dont-email.me> (permalink)
References <30urs79vrgihohjaoca4g3bj1kfbcqa5jk@4ax.com> <jql115$4v4$1@dont-email.me>

Show all headers | View raw


On 2012-06-05 09:19:33 -0400, James Kuyper wrote:
> On 06/05/2012 08:26 AM, George wrote:
[...]
>>   typedef void (*VOID_FNC)(void);
[...]
> The expansion is actually
> 
> 	(const VOID_FUNC)NullScrnFnc
> 
> The equivalent without use of typedefs would be:
> 
> 	(void(*)(void) const)NullScrnFnc

This is a syntax error.  I think you meant:

  (void(* const)(void))NullScrnFnc

> In other words, it is an expression declaring that NullScrnFnc is an
> object of type (void(*)(void) const).

It doesn't declare anything, and that again is not a valid type name.

> A typedef is not simply a macro, which is why the const needs to be moved to
> the end of the cast. In an expression like "const int i", the keyword const
> modifies 'i'; the same is true in "const VOID_FUNC NullScrnFnc". However, if
> we were to write "const void(*)(void) NullScrnFnc",

Another syntax error... I think you meant:

  const void(*NullScrnFnc)(void)

> then the 'const' would (with undefined behavior - 6.7.3p9) modify the return
> type from the function.

Assuming the above correction is what you meant, C11 6.7.3p9 does not
apply since (as you have stated) the qualifier applies to the return
type (which is not a function type), not the function type itself.  The
only way to actually qualify a function type or an array type (and thus
make 6.7.3p9 apply) is by using a typedef, as in:

  typedef void func_type(void);
  const func_type explode; /* qualified function type, UB by C11 6.7.3p9 */

Of course, const-qualifying the return type of a function make little
sense (especially if it's void!), but it is nevertheless valid.

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


Thread

interpret this code? George <gbeccles@verizon.net> - 2012-06-05 08:26 -0400
  Re: interpret this code? James Kuyper <jameskuyper@verizon.net> - 2012-06-05 09:19 -0400
    Re: interpret this code? Nick Bowler <nbowler@draconx.ca> - 2012-06-05 15:55 +0000
      Re: interpret this code? James Kuyper <jameskuyper@verizon.net> - 2012-06-05 12:05 -0400
  Re: interpret this code? "BartC" <bc@freeuk.com> - 2012-06-05 14:42 +0100
    Re: interpret this code? Noob <root@127.0.0.1> - 2012-06-05 16:19 +0200
  Re: interpret this code? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-05 14:43 +0100
  Re: interpret this code? Noob <root@127.0.0.1> - 2012-06-05 16:22 +0200
  Re: interpret this code? George <gbeccles@verizon.net> - 2012-06-05 22:50 -0400

csiph-web