Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: What are the odds? (a continuation of One works ...) Date: Wed, 06 Nov 2019 19:26:28 -0800 Organization: None to speak of Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="fdd2727d9421cbcb7e0942d3891e7ce6"; logging-data="8363"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+2ZZzrqeeawjvI69YlIsj" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:M+IiuxJAq+WwQfZtdGZi3/D/oDg= sha1:RmfvM+x6Y5MQzRxp8n5DTIwXz4Q= Xref: csiph.com comp.lang.c:147697 DFS writes: [...] > char charset[62] > ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; > int charsetLen = strlen(charset); > printf("%d \n",charsetLen); > 62 That still has undefined behavior. It appears to "work" only because, most likely, there just happens to be a null byte in memory immediately after charset. I just compiled and ran your on my system. I got 62 with gcc and clang, and 65 with tcc. There is not necessarily any particular reason for this, and it could just as easily produce different results tomorrow. > char charset[63] = > "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; > int charsetLen = strlen(charset); > printf("%d \n",charsetLen); > 62 That's well defined, but as I mentioned elsethread your (incorrect) strlen call is the only thing that relies on charset containing a valid string. If you define charset using [] you can get its size using sizeof. >> When you tested the code, did you not notice extraneous lines of >> output after the line for "9"? > > Not seeing that. Compiled and ran on tcc/Windows and gcc (MSYS2) and > there are no extraneous lines of output after the output for 9. That's one of thep problems with undefined behavior: it can evade testing. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */