From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bc1361a952ec75ca X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,582dff0b3f065a52 X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,582dff0b3f065a52 X-Google-Attributes: gid1014db,public X-Google-ArrivalTime: 2001-08-16 11:19:18 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!mencken.net.nih.gov!not-for-mail Message-ID: <3B7C0F90.EC31384B@sensor.com> From: Ron Natalie X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++ Subject: Re: How Ada could have prevented the Red Code distributed denial of service attack. References: <3b690498.1111845720@news.worldonline.nl> <9kbu15$9bj@augusta.math.psu.edu> <9kbvsr$a02@augusta.math.psu.edu> <3B69DB35.4412459E@home.com> <3B6F312F.DA4E178E@home.com> <23lok9.ioi.ln@10.0.0.2> <3B70AB15.35845A98@home.com> <3B721FF5.B7D854F6@home.com> <3B7BC847.61D7EF55@home.com> <3B7BCEC4.202A3FA@cfmu.eurocontrol.int> <3B7C0397.3AD029C6@home.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 16 Aug 2001 14:23:12 -0400 NNTP-Posting-Host: 156.40.240.200 X-Trace: mencken.net.nih.gov 997985958 156.40.240.200 (Thu, 16 Aug 2001 14:19:18 EDT) NNTP-Posting-Date: Thu, 16 Aug 2001 14:19:18 EDT Xref: archiver1.google.com comp.lang.ada:12003 comp.lang.c:74788 comp.lang.c++:83166 Date: 2001-08-16T14:23:12-04:00 List-Id: = > Re: sizeof "ab" returning 3 : > > I have personally run into this problem over the last decade or so > (but likely >= 1990 in this case). > > I don't have access to the other platforms where I used to program C, > but it may have been one of the following: SCO UNIX, Dec Alpha, or a > Solaris platform. By definition sizeof "ab" must be three. Normal string literals ("ab") must an array of three chars 'a', 'b', and '\0'. Sizeof is always in terms of chars. While you might think that native chars might be larger than 8 bits, the relationship between a normal string literal and char is fixed, as is the relationship of char to sizeof's return (that is sizeof (char) is always 1). This is one of the unfortunately mistakes in C and C++. char has two meanings. In one case it is the smallest addressable unit of storage and on the other hand it's used as a native character. If you wanted to make two byte native characters, you could do so (16 bit chars for example), but you would lose the ability to allocate and manipulate 8 bit things. As a result, any system that has a native character set bigger than what can be stored in char, pretty much does all it's work either in Multibyte representation or in wide chars (wchar_t's). Unfortunately, C and C++ doesn't support either one fully. The std::basic_string type can't deal with multibyte representations, where as numerous system interfaces (arg list, file names, exception->what, ...) can't deal with wchar's. C/C++'s idea of internationalization is pretty hopelessly half-assed.