digitalmars.D.bugs - synchronized nested function
- "Carlos Santander B." <carlos8294 msn.com> Sep 26 2004
- Sean Kelly <sean f4.ca> Sep 26 2004
- J C Calvarese <jcc7 cox.net> Sep 26 2004
- Ben Hinkle <bhinkle4 juno.com> Sep 26 2004
- "Carlos Santander B." <carlos8294 msn.com> Sep 26 2004
- Stewart Gordon <smjg_1998 yahoo.com> 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: # void main() { # synchronized { # void foo() {} # } # foo(); # } 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: # void main() { # void foo() { synchronized { # ... # } } # foo(); # } 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: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
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.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
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
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









Sean Kelly <sean f4.ca> 