Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #385966
| Path | csiph.com!news.swapon.de!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 20:56:41 -0700 |
| Organization | None to speak of |
| Lines | 33 |
| Message-ID | <87msnm505i.fsf@nosuchdomain.example.com> (permalink) |
| 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> <87r0cz3rx5.fsf@nosuchdomain.example.com> <666d0f4f$0$979$882e4bbb@reader.netnews.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Date | Sat, 15 Jun 2024 05:56:42 +0200 (CEST) |
| Injection-Info | dont-email.me; posting-host="1789de65328af8c5f284241bfaa69959"; logging-data="3475964"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sN+NwAy6bK81w7HEMHR73" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
| Cancel-Lock | sha1:B8euR9VZwtZH+JivdR9JNEzcOew= sha1:l5kfQVj4aB+xdQwo+I1mrFsDBqM= |
| Xref | csiph.com comp.lang.c:385966 |
Show key headers only | View raw
DFS <nospam@dfs.com> writes:
> On 6/14/2024 9:39 PM, Keith Thompson wrote:
>> 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.)
>
> I was surprised python did that, since every division used in the
> array addressing results in an integer.
>
> After casting i to an int before any array addressing, // works.
I'm surprised you needed to convert i to an int. I would think that
just replacing nums[i/2] by nums[i//2] would do the trick, as long
as i always has an int value (note Python's dynamic typing). If i
is acquiring a float value, that's probably a bug, given the name.
But if you want help with your Python code, comp.lang.python is the
place to ask.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
"undefined behavior"? DFS <nospam@dfs.com> - 2024-06-12 16:47 -0400
Re: "undefined behavior"? Barry Schwarz <schwarzb@delq.com> - 2024-06-12 14:30 -0700
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-12 17:53 -0400
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-12 15:30 -0700
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-12 19:07 -0400
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-12 17:33 -0700
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-13 05:47 +0100
Re: "undefined behavior"? scott@slp53.sl.home (Scott Lurndal) - 2024-06-13 15:39 +0000
Re: "undefined behavior"? Ben Bacarisse <ben@bsb.me.uk> - 2024-06-13 18:08 +0100
Re: "undefined behavior"? bart <bc@freeuk.com> - 2024-06-13 19:01 +0100
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-13 19:54 +0100
Re: "undefined behavior"? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-06-13 12:34 -0700
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-14 00:32 +0100
Re: "undefined behavior"? Ben Bacarisse <ben@bsb.me.uk> - 2024-06-14 00:55 +0100
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-14 02:48 +0100
Re: "undefined behavior"? Ben Bacarisse <ben@bsb.me.uk> - 2024-06-14 12:44 +0100
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-14 15:30 +0100
Re: "undefined behavior"? Richard Harnden <richard.nospam@gmail.invalid> - 2024-06-14 16:32 +0100
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-14 19:06 +0100
Re: "undefined behavior"? bart <bc@freeuk.com> - 2024-06-14 19:31 +0100
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-14 20:13 +0100
Re: "undefined behavior"? Ben Bacarisse <ben@bsb.me.uk> - 2024-06-14 22:29 +0100
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-14 23:35 +0100
Re: "undefined behavior"? Ben Bacarisse <ben@bsb.me.uk> - 2024-06-15 00:14 +0100
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-15 20:57 +0200
Re: "undefined behavior"? Richard Harnden <richard.nospam@gmail.invalid> - 2024-06-15 20:27 +0100
Re: "undefined behavior"? Ben Bacarisse <ben@bsb.me.uk> - 2024-06-15 23:13 +0100
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-16 12:53 +0200
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-16 14:44 +0100
Re: "undefined behavior"? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-06-14 11:49 -0700
Re: "undefined behavior"? Ben Bacarisse <ben@bsb.me.uk> - 2024-06-14 22:32 +0100
Re: "undefined behavior"? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-06-15 00:56 -0700
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-13 15:58 -0700
Re: "undefined behavior"? bart <bc@freeuk.com> - 2024-06-14 02:18 +0100
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-14 19:08 +0200
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-14 12:34 -0700
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-15 22:13 +0200
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-14 13:43 -0700
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-13 14:47 -0700
Re: "undefined behavior"? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2024-06-14 00:41 +0100
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-13 17:09 -0700
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-12 23:38 +0200
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-12 15:18 -0700
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-13 14:42 +0200
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-13 16:39 -0700
Re: "undefined behavior"? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-06-18 17:23 -0700
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-18 17:42 -0700
Re: "undefined behavior"? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-06-22 09:28 -0700
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-12 18:29 -0400
Re: "undefined behavior"? Ike Naar <ike@sdf.org> - 2024-06-13 07:25 +0000
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-13 11:13 -0400
Re: "undefined behavior"? scott@slp53.sl.home (Scott Lurndal) - 2024-06-13 15:40 +0000
Re: "undefined behavior"? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2024-06-13 15:49 +0000
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-13 13:05 -0400
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-13 15:15 +0200
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-13 16:47 -0700
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-14 19:13 +0200
Re: "undefined behavior"? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-06-12 23:38 +0200
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-12 15:22 -0700
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-12 18:34 -0400
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-13 15:21 +0200
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-13 10:38 -0400
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-14 19:18 +0200
Re: "undefined behavior"? scott@slp53.sl.home (Scott Lurndal) - 2024-06-14 17:36 +0000
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-15 22:15 +0200
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-14 19:05 -0400
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-14 18:39 -0700
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-14 23:49 -0400
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-14 20:56 -0700
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-15 00:45 -0400
Re: "undefined behavior"? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-06-15 07:03 +0200
Re: "undefined behavior"? DFS <nospam@dfs.com> - 2024-06-15 07:39 -0400
Re: "undefined behavior"? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-06-15 01:05 -0400
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-14 22:20 -0700
Re: "undefined behavior"? bart <bc@freeuk.com> - 2024-06-15 09:37 +0100
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-15 22:22 +0200
Re: "undefined behavior"? Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-06-13 02:19 +0200
Re: "undefined behavior"? David Brown <david.brown@hesbynett.no> - 2024-06-13 15:28 +0200
Re: "undefined behavior"? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-12 14:57 -0700
Re: "undefined behavior"? bart <bc@freeuk.com> - 2024-06-13 10:43 +0100
Re: "undefined behavior"? Bonita Montero <Bonita.Montero@gmail.com> - 2024-06-13 11:45 +0200
csiph-web