Talk About Network

Google





Programming > C - C++ Learning > Re: If NULL End...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 18 of 19 Topic 4067 of 4400
Post > Topic >>

Re: If NULL Ends a String or Char[], How to Send NULL to a File?

by "Ralph D. Ungermann" <usenet@[EMAIL PROTECTED] > Mar 13, 2008 at 06:57 PM

Philip Potter wrote:
> Ralph D. Ungermann wrote:
>> Hal Vaughan wrote:
>>> Since a NULL terminates a string
>>
>> Nope. But there is the concept of "Null-Terminated Byte Strings"
(NTBS):
>> many functions treat a '\0' as the end of the string.
> 
> In C, a string is terminated by a '\0' by definition (see n1256, the 
> latest C draft, section 7.1.1). If it isn't terminated by a '\0', it's 
> not a string.

Thanks! I've been looking closely to "6.4.5 String Literals", but 
somehow I missed the footnote, and hence the full definition of "string".

For total confusion: C++ talks about "Character sequences" and 
"null-terminated byte strings" (17.3.2.1.3). Both seem to allow '\0' 
anywhere, while a C string definitely ends with the first  '\0'.

But the message to the OP is: A '\0' in the middle is absolutely ok in 
C/C++, but you must not name it "string". His terminus "series of codes" 
is fine, he just must take care not to mix it with "strings".


> Nevertheless, a string literal may not be a good choice if it is to be 
> output as an array of bytes, because of the implicit '\0' at the end:

I'm still familar with C89 constructs like

char key[4] = "1234"; // no '\0' appended

but now I find, that this is ill-formed in C++. Hence, I fully agree, 
that string literals are not merely doubtful, but totally useless for 
the OP's purpose.


>>    unsigned char dev_out[6] = { '\0x03', '\0', 0, 255, 'x', '\r' };
> 
> ITYM '\x03' above.

Yes, of course!

-- ralph
 




 19 Posts in Topic:
If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 08:28:33 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 10:33:41 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 13:38:19 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 14:00:08 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 14:27:55 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 14:35:06 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 14:38:36 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 16:14:14 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 16:47:31 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"R. Scott Mellow&quo  2008-03-13 13:07:37 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 18:59:08 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"Ralph D. Ungermann&  2008-03-13 15:03:06 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Hal Vaughan <hal@[EMAI  2008-03-13 16:56:49 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Richard Heathfield <rj  2008-03-13 17:04:36 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Anand Hariharan <mailt  2008-03-13 15:45:18 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"Ralph D. Ungermann&  2008-03-13 14:38:28 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
Philip Potter <pgp@[EM  2008-03-13 16:20:55 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"Ralph D. Ungermann&  2008-03-13 18:57:23 
Re: If NULL Ends a String or Char[], How to Send NULL to a File?
"Ed Norris" <  2008-03-15 20:05:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 9:27:14 PST 2009.