Board index » off-topic » How to access array element in struct member
Apprentice
Delphi Developer |
Apprentice
Delphi Developer |
How to access array element in struct member2004-04-03 02:50:37 AM off-topic15 In the following code szCSDVersion is a struct member holding a string. I need to have access to the second byte of that string. This is the working MASM version: cmp [esi].OSVERSIONINFOEX.szCSDVersion[1], 'A' When I port it to a TASM version: cmp [(OSVERSIONINFOEX esi).szCSDVersion[1]], 'A' I get a "Need right square bracket" error. I've tried replacing [1] with (1) and <1>, but to no avail. How can this be solved? Thanks |
Bob Gonder
Delphi Developer |
2004-04-03 07:21:06 AM
Re:How to access array element in struct member
Apprentice wrote:
Quotecmp [(OSVERSIONINFOEX esi).szCSDVersion[1]], 'A' or cmp byte ptr[ esi.szCSDVersion +1], 'A' |
Apprentice
Delphi Developer |
2004-04-03 07:54:49 PM
Re:How to access array element in struct member
Nope, I don't think this has anything to do with C syntax.
Your first solution gives me the same error I originally had, and your second solution throws a "Pointer expression needs brackets" error. I hope someone has the answer, because everything I tried so far was a failure. {smallsort} |
Vasya Pupkin
Delphi Developer |
2004-04-03 10:07:58 PM
Re:How to access array element in struct member
Hi Apprentice,
[...] QuoteI hope someone has the answer, because everything I tried so far was a or using additional parenthesis: cmp [((OSVERSIONINFOEX esi).szCSDVersion)+1],'A' |
Bob Gonder
Delphi Developer |
2004-04-04 03:04:00 AM
Re:How to access array element in struct member
Apprentice wrote:
QuoteNope, I don't think this has anything to do with C syntax. would be +2, etc.) QuoteYour first solution gives me the same error I originally had, and your second solution throws a "Pointer expression needs brackets" error. Or do as Vasya said. QuoteI hope someone has the answer, because everything I tried so far was a failure. inc esi cmp byte ptr[ (OSVERSIONINFOEX esi).szCSDVersion ] ,'A' dec esi ;if you want to preserve esi If these things don't fix it, then you need to take a good look at your definition of OSVERSIONINFOEX and szCSDVersion. The 2 errors you have shown are about mismatching [ ], either too many or too few. (Original error) "Need right square bracket" Means: No Right Bracket. (Second error) "Pointer expression needs brackets" Means: No Left Bracket. Given that we are using the proper number of [ ] in the above code, that would mean that something in the definition of OSVERSIONINFOEX or szCSDVersion is messing it up. In non-IDEAL mode, you should be able to do this: cmp byte ptr[ esi + szCSDVersion +1 ] ,'A' if szCSDVersion is properly defined. |
Apprentice
Delphi Developer |
2004-04-04 04:50:46 AM
Re:How to access array element in struct member
Thanks Bob, I've tried Vasya's solution and it works.
QuoteIf these things don't fix it, then you need to take a good live with any design flaws in it. In this case, however, there's no design flaw whatsoever. It's just TASM that's nagging me, while in MASM this can be handled smoothly. Second, I'm using ideal mode, so anything like cmp byte ptr[ .... doesn't work there. And I really don't feel like switching between TASM and MASM mode all the time. Thanks again Regards Apprentice |
Bob Gonder
Delphi Developer |
2004-04-04 12:12:13 PM
Re:How to access array element in struct member
Apprentice wrote:
QuoteFor your information: OSVERSIONINFOEX is an existing structure definition of the API) _could_ be "wrong" for Tasm. QuoteSecond, I'm using ideal mode, so anything like on it to do the "right" thing, as you just never know when the "right" thing isn't what you intended. |
Apprentice
Delphi Developer |
2004-04-04 11:42:12 PM
Re:How to access array element in struct memberQuoteYour headers (compiler specific definition of the API) structs, and so on when I need them from the C/C++ header files of the C++Builder package. Anyway, this is my implementation of the OSVERSIONINFOEX struct: STRUC OSVERSIONINFOEXA dwOSVersionInfoSize DD ? dwMajorVersion DD ? dwMinorVersion DD ? dwBuildNumber DD ? dwPlatformId DD ? szCSDVersion DB 128 dup (?) wServicePackMajor DW ? wServicePackMinor DW ? wSuiteMask DW ? wProductType DB ? wReserved DB ? ENDS As far as I can tell the struct is the same as the one in the MSDN Platform SDK Documentation (or the online version on the MSDN web site). If you think this is wrong, let me know. QuoteDocs say "byte ptr" works the same in Ideal and Masm modes doesn't work in ideal mode (I don't know about masm mode, I never use it. I only use masm mode when I'm using MASM, not TASM.) In ideal mode, you must use something like this: cmp [BYTE PTR (OSVERSIONINFOEX esi).szCSDVersion]..... the "byte ptr" must be inside the square brackets, or tasm32 throws an error when it compiles the code. |
Bob Gonder
Delphi Developer |
2004-04-05 02:07:00 AM
Re:How to access array element in struct member
Apprentice wrote:
QuoteI see. What headers are you using then? extrn GetConsoleMode:near extrn SetConsoleMode:near extrn SetConsoleCtrlHandler:near extrn SetConsoleTitleA:near And a few structs and equ's. No big deal. QuoteAnyway, this is my implementation of the OSVERSIONINFOEX struct: QuoteThat's not what I ment. I'm saying that through hoops to make a compiler happy. If you write a lot of Asm, all that extra typing adds up. |