What are SZ array?

  • Thread starter Thread starter qglyirnyfgfo
  • Start date Start date
Q

qglyirnyfgfo

I was reading an article regarding .Net arrays and on that article,
the author mentioned something about SZ arrays.

As far as I can tell, SZ arrays are one dimension arrays that are zero
based, am I correct on this? Also, can someone tell me what does “SZ”
stands for?

Thank you.
 
Without a quote that provides enough context, I don't see how anyone could  
answer the question.

Pete

Quote:

Hi Pete,

---------------------------
Article quote:

When possible, you should try to stick with single-dimensioned, zero-
based arrays (sometimes referred to as SZ arrays or vectors).
---------------------------

Just curious if the term "SZ arrays" always refer to "single-
dimensioned, zero-based" or is the term used for other types. I am
also curious to know what "SZ" stands for, probably a C/C++ naming
conversion of some sort.

Thanks
 
This is probably referring to the way that strings were represented in C and
C++, before Unicode and other languages such as VB came along. Strings, in
those days and those languages, were maintained in memory as one-dimensional
arrays of bytes, with each byte containing a character (or 'char'). The
characters in the string were followed by a single byte with a value of
binary zero. This was also called a 'null byte', and one might say of such a
string that it was 'null-terminated'.

The byte array (or char array) was allocated at fixed length (the 'character
buffer') and the byte or character count included space for the terminating
null character. So a string variable could contain any number of characters,
including zero characters, up to the length of the buffer minus one, because
the null-terminating character had to be there to satisfy the C/C++ runtime
code. The C and C++ runtime understood this convention, and the programmer
had to as well, so as to always allocate string variables with enough space
to contain the terminating null character.

This convention has become one of the most popular attack vectors for
hacking - the "buffer overflow" that you always are hearing about - because
it's easy to store into one of those byte arrays a string that's longer than
the size of the array, and programmers are typically negligent about
checking that an input string is not too large to store into the space
allocated.

In Microsoft's ghastly old Hungarian notation - invented by Charles Simonyi
and badly misused by Microsoft programmers for a long time afterwards - it
was common to prefix the name of a string variable with the characters 'sz'
(meaning 'zero-terminated string').

This is still supported in Microsoft's C and C++ languages.

Tom Dacon
Dacon Software Consulting

Jon Skeet will be along in a minute to correct my account of this, so don't
consider this question answered until he has weighed in on the issue :-)


I was reading an article regarding .Net arrays and on that article,
the author mentioned something about SZ arrays.

As far as I can tell, SZ arrays are one dimension arrays that are zero
based, am I correct on this? Also, can someone tell me what does “SZ”
stands for?

Thank you.
 
I see from your follow-up post that the original author uses a different
meaning altogether for the term 'SZ array', so you may disregard my
explanation of a much different meaning of the term.

Tom Dacon
Dacon Software Consulting
 
I see from your follow-up post that the original author uses a different
meaning altogether for the term 'SZ array', so you may disregard my
explanation of a much different meaning of the term.

Actually, that’s a pretty good explanation.

So my guess is that the terminology has nothing to do with arrays as
we know them today.

It looks like the term simply stuck since C/C++ string are always
single-dimensioned, zero- based arrays of <chars>, then I can see how
the term got associated to today’s single-dimensioned, zero- based
array of <T>.

Thanks.
 
This naming convention and more regarding arrays is discussed quite
thoroughly in this month's VisualStudio Magazine.

I was reading an article regarding .Net arrays and on that article,
the author mentioned something about SZ arrays.

As far as I can tell, SZ arrays are one dimension arrays that are zero
based, am I correct on this? Also, can someone tell me what does “SZ”
stands for?

Thank you.
 
I'll ignore Tom's flamebait about Hungarian being "ghastly".

Not looking for trouble - just my opinion, but I agree that it might have
been better to have left out the adjective so as not to offend those who are
deeply invested in that particular style. However I do believe that there's
fairly broad agreement that Simonyi's original, good, and very useful
technique of semantic (not variable type) prefixes was badly distorted by
various programming groups at Microsoft.

If you have more to say on the topic - which I am not particularly
interested in pursuing - you might consider cracking a new thread instead of
continuing it here.

Tom
 
Actually, that’s a pretty good explanation.

So my guess is that the terminology has nothing to do with arrays as
we know them today.

It looks like the term simply stuck since C/C++ string are always
single-dimensioned, zero- based arrays of <chars>, then I can see how
the term got associated to today’s single-dimensioned, zero- based
array of <T>.

Not "zero-based". "zero-terminated" is the key point. And yes, it's
equally applicable to arrays of wchar_t as char, and can be extended to any
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top