digitalmars.D.bugs - synchronized nested function
- Carlos Santander B. (13/13) Sep 26 2004 I don't think the error message is appropiate for this situation:
- Sean Kelly (19/25) Sep 26 2004 No. "synchronized" is a statement identifier, so what you're doing is
- J C Calvarese (31/48) Sep 26 2004 Yeah, the error message seems pretty vague. Seems like it should
- Ben Hinkle (4/65) Sep 26 2004 The section on declarations about storage classes (why synchronized is
-
Carlos Santander B.
(27/27)
Sep 26 2004
"J C Calvarese"
escribió en el mensaje -
Stewart Gordon
(41/53)
Oct 21 2004
I don't think the error message is appropiate for this situation: ///////////////////////////// void main () { synchronized void foo () {} foo (); // ln 4 } // test.d(4): undefined identifier foo // test.d(4): function expected before (), not 'int' ///////////////////////////// BTW, should this work? ----------------------- Carlos Santander Bernal
Sep 26 2004
In article <cj7coo$nuc$1 digitaldaemon.com>, Carlos Santander B. says...void main () { synchronized void foo () {} foo (); // ln 4 } BTW, should this work?No. "synchronized" is a statement identifier, so what you're doing is equivalent to this: So by the time you try and call foo, the definition is out of scope. It's the declaration of foo that is synchronized in this case, not foo itself. For that, try this: Sean
Sep 26 2004
Carlos Santander B. wrote:I don't think the error message is appropiate for this situation: ///////////////////////////// void main () { synchronized void foo () {} foo (); // ln 4 } // test.d(4): undefined identifier foo // test.d(4): function expected before (), not 'int' /////////////////////////////Yeah, the error message seems pretty vague. Seems like it should complain on line 3 if it's going to complain.BTW, should this work?I don't think so. It looks like you're trying to use synchronized as an attribute when it's supposed to be a statement. Is there something in the spec that supports your usage? From http://www.digitalmars.com/d/statement.html#synchronize The synchronize statement wraps a statement with critical section to synchronize access among multiple threads. SynchronizeStatement: synchronized Statement synchronized ( Expression ) Statement Here are some guesses of what you might want... void main () { void foo () {} synchronized foo (); } Or maybe this? void main () { void foo () { synchronized {}; } foo (); } (I haven't tried either.)----------------------- Carlos Santander Bernal-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Sep 26 2004
J C Calvarese wrote:Carlos Santander B. wrote:The section on declarations about storage classes (why synchronized is considered a storage class?) mentions synchronized. Also it works when you use synchronized as an attribute for member functions.I don't think the error message is appropiate for this situation: ///////////////////////////// void main () { synchronized void foo () {} foo (); // ln 4 } // test.d(4): undefined identifier foo // test.d(4): function expected before (), not 'int' /////////////////////////////Yeah, the error message seems pretty vague. Seems like it should complain on line 3 if it's going to complain.BTW, should this work?I don't think so. It looks like you're trying to use synchronized as an attribute when it's supposed to be a statement. Is there something in the spec that supports your usage? From http://www.digitalmars.com/d/statement.html#synchronize The synchronize statement wraps a statement with critical section to synchronize access among multiple threads. SynchronizeStatement: synchronized Statement synchronized ( Expression ) StatementHere are some guesses of what you might want... void main () { void foo () {} synchronized foo (); } Or maybe this? void main () { void foo () { synchronized {}; } foo (); } (I haven't tried either.)----------------------- Carlos Santander Bernal
Sep 26 2004
"J C Calvarese" <jcc7 cox.net> escribió en el mensaje news:cj7fgk$p0v$1 digitaldaemon.com... | ... | | Here are some guesses of what you might want... | | void main () | { | void foo () {} | synchronized foo (); | } | | | Or maybe this? | | void main () | { | void foo () { | synchronized {}; | } | foo (); | } | | Thank you, guys. ----------------------- Carlos Santander Bernal
Sep 26 2004
J C Calvarese wrote: <snip>It looks like you're trying to use synchronized as an attribute when it's supposed to be a statement. Is there something in the spec that supports your usage? From http://www.digitalmars.com/d/statement.html#synchronize The synchronize statement wraps a statement with critical section to synchronize access among multiple threads. SynchronizeStatement: synchronized Statement synchronized ( Expression ) Statement<snip> Really, there's a parsing ambiguity here. It could be either a SynchronizeStatement or a Declaration. The conflict resolution rules happen to favour the SynchronizeStatement interpretation. Separating Statement from DeclarationStatement should fix it: Statement: LabeledStatement BlockStatement ExpressionStatement IfStatement DebugStatement VersionStatement WhileStatement DoWhileStatement ForStatement ForeachStatement SwitchStatement CaseStatement DefaultStatement ContinueStatement BreakStatement ReturnStatement GotoStatement WithStatement SynchronizeStatement TryStatement ThrowStatement VolatileStatement AsmStatement PragmaStatement StatementList: Statement DeclarationStatement Statement StatementList DeclarationStatement StatementList The definition of DeclarationStatement looks wrong anyway - it doesn't cover nested functions at all. Should DeclarationStatement be any different from Declaration, FTM? Stewart.
Oct 21 2004