www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - (a) & b parsed as cast expr!

reply bug d.com writes:
======================================== op.d ===
int main(char[][] args)
{
int a, b, c;

c = (a) & b;  // a & b works, b & (a) works
return 0;
}
======================================== op.d ===

$ dmd op.d
op.d(5): C style cast deprecated, use cast(a)(#b)
Jan 12 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
bug d.com wrote:
 ======================================== op.d ===
 int main(char[][] args)
 {
 int a, b, c;
 
 c = (a) & b;  // a & b works, b & (a) works
 return 0;
 }
 ======================================== op.d ===
 
 $ dmd op.d
 op.d(5): C style cast deprecated, use cast(a)(#b)

Been mentioned a few times. It's just a limitation of context-free parsing coupled with a grammar that isn't quite made for it. Once C-style casts finally get removed from the language, it'll work. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 13 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
news:cs60b2$2j0o$1 digitaldaemon.com...
 bug d.com wrote:
 ======================================== op.d ===
 int main(char[][] args)
 {
 int a, b, c;

 c = (a) & b;  // a & b works, b & (a) works
 return 0;
 }
 ======================================== op.d ===

 $ dmd op.d
 op.d(5): C style cast deprecated, use cast(a)(#b)

Been mentioned a few times. It's just a limitation of context-free parsing coupled with a grammar that isn't quite made for it. Once C-style casts finally get removed from the language, it'll work.

True. I should also point out that while putting pointless parentheses around expressions is common in C (because of macro argument expansions), they are unnecessary in D, so this bug shouldn't cause significant problems.
Jan 15 2005
next sibling parent reply bug d.com writes:
In article <cscvki$10av$1 digitaldaemon.com>, Walter says...
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
news:cs60b2$2j0o$1 digitaldaemon.com...
 bug d.com wrote:
 ======================================== op.d ===
 int main(char[][] args)
 {
 int a, b, c;

 c = (a) & b;  // a & b works, b & (a) works
 return 0;
 }
 ======================================== op.d ===

 $ dmd op.d
 op.d(5): C style cast deprecated, use cast(a)(#b)

Been mentioned a few times. It's just a limitation of context-free parsing coupled with a grammar that isn't quite made for it. Once C-style casts finally get removed from the language, it'll work.

True. I should also point out that while putting pointless parentheses around expressions is common in C (because of macro argument expansions), they are unnecessary in D, so this bug shouldn't cause significant problems.

The code actually is generated by a tool :-) D compiler should be friendly with code-generation tools, to make D more popular.
Jan 15 2005
parent reply "Walter" <newshound digitalmars.com> writes:
<bug d.com> wrote in message news:csd25m$12f6$1 digitaldaemon.com...
True. I should also point out that while putting pointless parentheses
around expressions is common in C (because of macro argument expansions),
they are unnecessary in D, so this bug shouldn't cause significant


 The code actually is generated by a tool :-)

I hadn't thought of that. You can make it work by adding a unary +, as in (+p).
 D compiler should be friendly with code-generation tools, to make D more
 popular.

I agree.
Jan 19 2005
parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Walter" <newshound digitalmars.com> wrote in message
news:csn5bj$157d$3 digitaldaemon.com...
 <bug d.com> wrote in message news:csd25m$12f6$1 digitaldaemon.com...
True. I should also point out that while putting pointless parentheses
around expressions is common in C (because of macro argument



they are unnecessary in D, so this bug shouldn't cause significant


 The code actually is generated by a tool :-)

I hadn't thought of that. You can make it work by adding a unary +, as in (+p).

That is a great idea, my tool also generates a code that looks like this and this will fix it. :) But i hope that removing c-style casts will fix this? It would be better to remove c-cast code sooner to have more time to fix bugs that might be caused by removing it.
 D compiler should be friendly with code-generation tools, to make D more
 popular.

I agree.

Jan 22 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Ivan Senji wrote:
<snip>
 But i hope that removing c-style casts will fix this? It would be
 better to remove c-cast code sooner to have more time to fix bugs
 that might be caused by removing it.

Really? Do that many people compile in deprecated mode for everyday purposes? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 24 2005
parent reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
news:ct2mrm$qoq$1 digitaldaemon.com...
 Ivan Senji wrote:
 <snip>
 But i hope that removing c-style casts will fix this? It would be
 better to remove c-cast code sooner to have more time to fix bugs
 that might be caused by removing it.

Really? Do that many people compile in deprecated mode for everyday purposes?

I don't! But maybe you didn't understand me (and i can't blame you because of my English): I wanted to write: In the compiler there is code that parses c-casts and causes wrong messages about c cast when what you are trying to do has nothing to do with casting. Like in: int abc,def; def = (abc) + 2; Now it will probbably be fixed by removing c-casts code, and enable the above code to be parsed as an assignement, but removing that code could also result in new bugs. And we don't need them :)
 Stewart.

 --
 My e-mail is valid but not my primary mailbox.  Please keep replies on
 the 'group where everyone may benefit.

Jan 24 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Ivan Senji wrote:
<snip>
 Now it will probbably be fixed by removing c-casts code, and enable 
 the above code to be parsed as an assignement, but removing that code 
 could also result in new bugs. And we don't need them :)

Would you care to be specific? What new bugs would it cause? Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 24 2005
parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
news:ct35a9$1e2r$1 digitaldaemon.com...
 Ivan Senji wrote:
 <snip>
 Now it will probbably be fixed by removing c-casts code, and enable
 the above code to be parsed as an assignement, but removing that code
 could also result in new bugs. And we don't need them :)

Would you care to be specific? What new bugs would it cause?

I didn't say would, i said could. You can never know what problems removing or adding code can cause. So i can't be specific, just a precaution, if any bugs come it is better to be sooner :-)
 Stewart.

 --
 My e-mail is valid but not my primary mailbox.  Please keep replies on
 the 'group where everyone may benefit.

Jan 24 2005
prev sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Walter wrote:

Been mentioned a few times.  It's just a limitation of context-free
parsing coupled with a grammar that isn't quite made for it.  Once
C-style casts finally get removed from the language, it'll work.

True. I should also point out that while putting pointless parentheses around expressions is common in C (because of macro argument expansions), they are unnecessary in D, so this bug shouldn't cause significant problems.

Some people put extra parenthesis to make later maintenance easier, just as they put extra braces on the if and else statement blocks... But that's really besides the point. D is not source-compatible with C, so the code-generator tool mentioned just seems to be broken... :-) If there is a more complex generator than the "a,b,c" example lurking behind-the-scenes, it would be interesting to see some real code... Otherwise, just drop the parens. Just like with functions: (void) => () --anders
Jan 16 2005
parent bug d.com writes:
In article <csdv2i$1vhh$1 digitaldaemon.com>,
=?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...
Walter wrote:

Been mentioned a few times.  It's just a limitation of context-free
parsing coupled with a grammar that isn't quite made for it.  Once
C-style casts finally get removed from the language, it'll work.

True. I should also point out that while putting pointless parentheses around expressions is common in C (because of macro argument expansions), they are unnecessary in D, so this bug shouldn't cause significant problems.

Some people put extra parenthesis to make later maintenance easier, just as they put extra braces on the if and else statement blocks... But that's really besides the point. D is not source-compatible with C, so the code-generator tool mentioned just seems to be broken... :-)

No one mentioned that the tool is a dedicated C tool. There's only one question here: puting extra parenthesis around 'a' is valid D syntax or not. If it is, then the DMD compiler should be fixed. Otherwise, the tool should be fixed. Make simple things simple.
If there is a more complex generator than the "a,b,c" example lurking
behind-the-scenes, it would be interesting to see some real code...

Otherwise, just drop the parens. Just like with functions: (void) => ()

--anders

Jan 16 2005