Re: Terminology concerning strings


On Mon, 4 Apr 2005, Roland Illig wrote:

> Hi all,
> in the last time I have programmed a bit with strings, and I have found
> four properties of them which need to be distinguished and which should
> be named consistently throughout the whole Midnight Commander.
> * the _size_ of a string (as well as for other objects) is the number of
>    bytes that is allocated for it. For arrays, it is the number of
>    entries of the array. For strings it is at least _length_ + 1.
> * the _length_ of a string is the number of characters in it, excluding
>    the terminating '\0'.

Wow! Btw you speak of null terminated strings here. The length of the
string is always the number of characters in it no matter how do you
represent a string. As about the size it depends on the string

> Currently these differences are not recognized by most of the code.
> Therefore I'd like to rename all matching variables according to this
> scheme: For the string variable s, the _size_ is called ssize, the
> _length_ is called slen, the _width_ is called swidth, and the _height_
> is called sheight.
> Example:
>      char *fname = g_strdup (s);
>      size_t fnamewidth, fnameheight, fnamesize, fnamelen;

My personal preference is to prepend an underscore to the property
tag i.e:

  `fname_width' instead of `fnamewidth'

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]