digitalmars.D.learn - Compiler doesn't complain with multiple definitions
- ric maicle (16/16) Nov 11 2015 I was playing with __traits and tried the code below.
- anonymous (6/22) Nov 12 2015 __traits has special syntax. The first "argument" must be from a list of...
- ric maicle (5/10) Nov 12 2015 Thanks for clarifying __traits.
- John Colvin (4/20) Nov 12 2015 If I remember correctly:
I was playing with __traits and tried the code below. Shouldn't the compiler emit a warning that I'm defining isPOD multiple times and/or I'm defining something that is built-in like isPOD? // DMD64 D Compiler v2.069 import std.stdio; struct isPOD { bool status = false; } int main() { byte isPOD = 0; writeln(isPOD); writeln(__traits(isPOD, typeof(isPOD))); return 0; }
Nov 11 2015
On 12.11.2015 06:27, ric maicle wrote:I was playing with __traits and tried the code below. Shouldn't the compiler emit a warning that I'm defining isPOD multiple times and/or I'm defining something that is built-in like isPOD? // DMD64 D Compiler v2.069 import std.stdio; struct isPOD { bool status = false; } int main() { byte isPOD = 0; writeln(isPOD); writeln(__traits(isPOD, typeof(isPOD))); return 0; }__traits has special syntax. The first "argument" must be from a list of special keywords that only have special meaning in that place. You can't put the name of a struct there, and you can't put the special keyword anywhere else. So there's no ambiguity, and you're not redefining anything. Everything's fine.
Nov 12 2015
On Thursday, 12 November, 2015 07:50 PM, anonymous wrote:__traits has special syntax. The first "argument" must be from a list of special keywords that only have special meaning in that place. You can't put the name of a struct there, and you can't put the special keyword anywhere else. So there's no ambiguity, and you're not redefining anything. Everything's fine.Thanks for clarifying __traits. On another thing. I'm wondering why the compiler didn't issue a warning on struct isPOD and byte isPOD? Isn't this called 'shadowing' or have I misunderstood the term?
Nov 12 2015
On Thursday, 12 November 2015 at 15:06:26 UTC, ric maicle wrote:On Thursday, 12 November, 2015 07:50 PM, anonymous wrote:If I remember correctly: Shadowing globals is allowed, all other instances of shadowing are not.__traits has special syntax. The first "argument" must be from a list of special keywords that only have special meaning in that place. You can't put the name of a struct there, and you can't put the special keyword anywhere else. So there's no ambiguity, and you're not redefining anything. Everything's fine.Thanks for clarifying __traits. On another thing. I'm wondering why the compiler didn't issue a warning on struct isPOD and byte isPOD? Isn't this called 'shadowing' or have I misunderstood the term?
Nov 12 2015