Re: DEC-C: Null string constant ?

From: David Froble (davef_at_tsoft-inc.com)
Date: 10/22/04


Date: Fri, 22 Oct 2004 02:55:03 -0400

briggs@encompasserve.org wrote:

> In article <4177CBED.40109@tsoft-inc.com>, David Froble <davef@tsoft-inc.com> writes:
>
>>JF Mezei wrote:
>>
>>
>>>char *mybuffer ;
>>>mybuffer = ""
>>>myroutine(mybuffer);
>>>
>>>----
>>>myroutine(char *mybuffer)
>>>{
>>>printf ("Address of string=>%ld\n", mybuffer);
>>>}
>>>
>>>Retults in a big fat value of 0, and of course, if you try to strlen(mybuffer)
>>>the program crashes.
>>>
>>>I was under the impression that "" yielded a valid string constant containing
>>>only the null character, and that you could use this to still provide a valid
>>>pointer address to the various routines in your applications.
>>>
>>
>>First note that my prefered language is BASIC, not C.
>>
>>A null is a valid character.
>>
>
> That statement is a tad strong. A null _can be_ a valid character.

To be a bit more precise, a null character is a valid character. ASCII value is
zero.

> Whether it is valid depends on context. It's a valid character
> in the ASCII code.
>
> But, if your context is a null-terminated string, then a null is not
> a valid character within the body of that string.
>
>
>>It takes one byte of storage for each character.
>>It is a bit tough to have a string of nulls when using null terminated strings.
>>
>
> Of course. As it happens, I find null-terminated strings distasteful
> as well. For this very reason.
>
> I have developed a distaste for VMS "can't be longer than 2^16 characters"
> string descriptors as well. It is a bit tough to encode a 100,000
> character string when strings are limited to 65535 characters.

I confess to curosity. What's the usage of such a long string?

> Ah well. Such is life. I don't much care for ASN.1 unlimited
> length encodings either. Guess there's no pleasing some people. :-)
>
>
>> Another shortcoming of that technique.
>>
>>A null string is a string with no characters, zero length.
>>
>
> True. And a null string encoded as a null-terminated string
> is a buffer containing a single null character.
>
> A null string encoded using a VMS descriptor is a quadword with a length
> code of zero and pointer that doesn't have to point anywhere special.

Well, you describe the descriptor, not the data. I've not looked, but I think
there might be a problem with a pointer to some location that will generate an
error, such as zero. Just guessing.

> A null string encoded as a counted string is a buffer containing
> a single zero byte.
>
> A null string encoded with ASN.1 is... I'd have to go look it
> up. *** sound of furious keyboard tapping *** ... A two byte
> buffer containing
>
> 0x4 (Universal, Primitive, Octet string)
> 0x0 (Short format, length 0)
> (String contents -- null)
>
> John Briggs
>

-- 
David Froble                       Tel: 724-529-0450
Dave Froble Enterprises, Inc.      Fax: 724-529-0596
DFE Ultralights, Inc.              E-Mail: davef@tsoft-inc.com
170 Grimplin Road
Vanderbilt, PA  15486


Relevant Pages

  • [TOMOYO #15 3/8] Common functions for TOMOYO Linux.
    ... This file contains common functions (e.g. policy I/O, pattern matching). ... Since TOMOYO Linux is a name based access control, ... TOMOYO Linux's string manipulation functions make reviewers feel crazy, ... the Linux kernel accepts all characters but NUL character ...
    (Linux-Kernel)
  • Re: Will standard C++ allow me to replace a string in a unicode-encoded text file?
    ... >> You really should check that the other bytes are zero, as well, and give ... >> normal string, unless you're on an implementation with 16 bit or more ... >> to an error character ('?' ... > byte-order mark is \0 for all chars in the file). ...
    (comp.lang.cpp)
  • Re: Admired designs / designs to study
    ... instructions to try to pack together a whole word ... resort to using one of the string or bit move ... Get the next character from the ... if the number isn't zero yet. ...
    (comp.arch)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)