admin管理员组

文章数量:1406937

I have a method in a Bcrypt algorithm that would of originally come from here /tree/main which has the following syntax:

 for (int offset = 0, c1, c2; offset < length; )
 {
   ...
 }

Notice the two arguments c1 and c2 in the condition position. But I cant find any documentation supporting this syntax

This used to build using older versions (and still does build using older versions tested on 17.12.4) of visual studio but no longer builds with version 17.13.2 But the latest version of visual studio it throws the following build error

';' expected

I noticed in the source code for Bcrypt they actually refactored this to use a while loop /blob/main/src/BCrypt.Net/BCryptBase.cs#L401 but I'm reluctant to refactor this as it's the authentication for my website and there would be risk associated with refactoring or updating the code

Is the syntax of multiple condition arguments valid and this is a visual studio bug or am I missing something?

I have a method in a Bcrypt algorithm that would of originally come from here https://github/BcryptNet/bcrypt/tree/main which has the following syntax:

 for (int offset = 0, c1, c2; offset < length; )
 {
   ...
 }

Notice the two arguments c1 and c2 in the condition position. But I cant find any documentation supporting this syntax https://learn.microsoft/en-us/dotnet/csharp/language-reference/statements/iteration-statements#the-for-statement

This used to build using older versions (and still does build using older versions tested on 17.12.4) of visual studio but no longer builds with version 17.13.2 But the latest version of visual studio it throws the following build error

';' expected

I noticed in the source code for Bcrypt they actually refactored this to use a while loop https://github/BcryptNet/bcrypt/blob/main/src/BCrypt.Net/BCryptBase.cs#L401 but I'm reluctant to refactor this as it's the authentication for my website and there would be risk associated with refactoring or updating the code

Is the syntax of multiple condition arguments valid and this is a visual studio bug or am I missing something?

Share Improve this question edited Mar 4 at 10:20 JKennedy asked Mar 4 at 9:27 JKennedyJKennedy 18.8k21 gold badges127 silver badges214 bronze badges 15
  • 1 It's normal syntax for declaring multiple variables. The line int offset = 0, c1, c2; is basically the same as int offset = 0; int c1; int c2;. – NotFound Commented Mar 4 at 9:34
  • 3 For for (int offset = 0, c1, c2; offset < length; ) you have initialization as int offset = 0, c1, c2 condition offset < length and empty iteration – Dmitrii Bychenko Commented Mar 4 at 9:42
  • 2 This is defined here and more specifically here. Note that the definition of local_variable_declaration states that it "declares one or more local variables" – Matthew Watson Commented Mar 4 at 10:05
  • 1 I think this is broken with visual studio V17.13.0 and higher. It works with older versions, which is probably why dotnetfiddle works – JKennedy Commented Mar 4 at 10:08
  • 4 "it throws a build error" - what error? It's always worth including the details of an error/exception rather than just saying that one is produced. This question would be so much better with a minimal reproducible example including all relevant version information and the error you observe. – Jon Skeet Commented Mar 4 at 10:12
 |  Show 10 more comments

1 Answer 1

Reset to default 1

This was a bug. I reported it when downgrading to 17.12.4, they said the fix was already in the pipeline.

I've verified it's fixed in 17.13.3.

本文标签: visual studioIs a For loop with multiple initialisation arguments in c validStack Overflow