Deutsch English Français Italiano |
<87r0cz3rx5.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.lang.c Subject: Re: "undefined behavior"? Date: Fri, 14 Jun 2024 18:39:50 -0700 Organization: None to speak of Lines: 22 Message-ID: <87r0cz3rx5.fsf@nosuchdomain.example.com> References: <666a095a$0$952$882e4bbb@reader.netnews.com> <v4d4hm$1rjc5$1@dont-email.me> <8734ph7qe5.fsf@nosuchdomain.example.com> <666a226d$0$951$882e4bbb@reader.netnews.com> <v4erpi$29e2g$2@dont-email.me> <666b0451$0$953$882e4bbb@reader.netnews.com> <v4hu1b$2ve93$3@dont-email.me> <666ccccb$0$973$882e4bbb@reader.netnews.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sat, 15 Jun 2024 03:39:51 +0200 (CEST) Injection-Info: dont-email.me; posting-host="1789de65328af8c5f284241bfaa69959"; logging-data="3307929"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Vs7043cxzv5SnY43OkS/j" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:BOSDDogkyLHtB6RmLauwpmEVE98= sha1:I6uKv3tL2XKgHpLPK4mRzYYOKbc= Bytes: 1955 DFS <nospam@dfs.com> writes: [...] > During conversion, I got a Python error I don't remember seeing in the past: > > "TypeError: list indices must be integers or slices, not float" > > because division returns a float, and some of the array addressing was > like this: nums[i/2]. [...] C's "/" operator yields a result with the type of the operands (after promotion to a common type). Python's "/" operator yields a floating-point result. For C-style integer division, Python uses "//". (Python 2 is more C-like.) See https://docs.python.org/3/ or comp.lang.python, which is reasonably active. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */