Size of Char[] array?

This forum is meant for questions and discussions about the X# language and tools
Post Reply
stefan.ungemach
Posts: 71
Joined: Thu Jul 15, 2021 10:46 am
Location: Germany

Size of Char[] array?

Post by stefan.ungemach »

This code gives me a warning XS9021 in the red line:

...
pResult := Char[]{dwResult}
XSharp.ADS.ACE.AdsGetString(self:_hADT, cFieldName, pResult, @dwResult, ADS_NONE)
...

PUBLIC STATIC METHOD AdsGetString(hTable As PTR, lFieldOrdinal As DWORD, pucBuf As CHAR[], pulLen Ref DWORD, usOption As WORD) As DWORD

Problem is that the called method wants a DWORD as 4. parameter, and it can indeed fill a buffer which is larger than MAX_WORD. How can I prepare a large buffer other than the red line's code?
User avatar
Chris
Posts: 4910
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Size of Char[] array?

Post by Chris »

Hi Stefan,

The constructor of the System.Array class expects an integer (elements of the array), that's why you get the warning. I guess it's very unlikely that the dwResult var will ever hold a number greater than MAX LONG INT :), so you can just convert it to INT: pResult := Char[]{ INT(dwResult) }
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
stefan.ungemach
Posts: 71
Joined: Thu Jul 15, 2021 10:46 am
Location: Germany

Size of Char[] array?

Post by stefan.ungemach »

Hi Chris, thanks, that did the trick.

BTW: Apologies for so many stupid questions, but I've finally started to migrate our complex VO framework to XSharp - and that's 1.5 millions of code lines ;)
User avatar
Chris
Posts: 4910
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Size of Char[] array?

Post by Chris »

Hi Stefan,

Please don't worry at all, there are no stupid questions :)
Good luck with your migration, please don't hesitate to ask anything!
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Size of Char[] array?

Post by robert »

Stefan
At first, it may look strange that some of these functions accept a signed number. How can you ever create an array with a negative number of elements?
The reason for this is that although the .Net system supports unsigned number, these were initially not part of what is called the Common Language Specification (CLS), so .Net languages did not have to support them to be "first class" .Net languages.

https://essentialcsharp.com/common-lang ... cification

Therefore, the constructors for many types only take signed integers.
And methods like IndexOf() and properties like Length also return signed integers. They often use -1 as special value to indicate that for example IndexOf() did not find anything.
The VO developers used 1 based indexes for characters in a string and elements in an array. They use 0 as special value and used unsigned integers for sizes and indices.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply