typeof and my crummy code...
    Bill Baxter 
    wbaxter at gmail.com
       
    Fri Nov  6 10:11:46 PST 2009
    
    
  
On Fri, Nov 6, 2009 at 9:02 AM, Ellery Newcomer
<ellery-newcomer at utulsa.edu> wrote:
> Another question: given
>
> import std.stdio;
> void main()
> {
>    int i( /*char*/ ){return 1;}
>    writeln(typeof(i).stringof);
> }
>
>
> This gives
>
> (int())()
That seems buggy to me.  I would expect it to say "int".
> and with the char uncommented it errors
That seems right.  i by itself is an attempt to call i with no
arguments.  You need to use & with functions if you want to avoid
that.
> * typeof doesn't evaluate the expression, according to the spec.
But it is supposed to figure out what the type would be if it /were/ evaluated.
> * then why does it matter if the function has its parameters applied above?
"i" is a valid call in the first case, not in the second case.
> * for a function sans params, there would be a semantic ambiguity (in D1
> land, at least) in typeof(i) (params applied, or no?)
You need to use & if you're talking about the function itself and not
what it evaluates to.
> * and for the case above, why the heck are we mixing expression and type
> in the string result?
I think that's a bug.  Does using &i give you the function type as expected?
--bb
    
    
More information about the Digitalmars-d-learn
mailing list