Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #162042
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: How to disambiguate macro? |
| Date | 2021-07-22 18:15 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <sdc5i6$4l2$1@dont-email.me> (permalink) |
| References | (11 earlier) <sd9ib5$qh1$1@dont-email.me> <sd9mhe$q8b$1@dont-email.me> <sd9tkt$edf$1@dont-email.me> <sdb4an$56m$1@dont-email.me> <sdbvrb$2s7$1@z-news.wcss.wroc.pl> |
On 22/07/2021 16:37, antispam@math.uni.wroc.pl wrote: > David Brown <david.brown@hesbynett.no> wrote: >> >> The way expressions are interpreted and evaluated is, in most languages, >> independent of what you do with the results. (The number of programming >> languages is so vast that there are bound to be exceptions to almost any >> rule or generalisation.) >> >> If you write : >> >> int x = 4 / 3; >> float y = 4 / 3; >> >> in most languages, you would not expect the first division to be done as >> integers and the second to be done as floating point. You would expect >> consistency. It might be consistently integer division, or consistently >> floating point (and then converted to integer x and floating point y). >> But you want consistency. > > There are languages that do overloading resolution based on result > type. In language that I frequently use both are wrong: division > on integers produces rational number and can not give back an integer. > Similarely, division for floats needs floats as arguments while > 3 and 4 are not floats. But there are valid expressions in similar > spirit: they will do different things depending on result type. > Overloading on the operand types is normal : float y = (float) 4 / 3; There are some languages that overload on result type too, but they are less common. > Probably the most prominent example of language that has overloading > on result type is Ada. However, IIUC in C++ it is possible to > have eqivalent effect. Of course, C++ keeps built-in stuff > reasonably compatible with C, so your examples work as in C. > But there are interesting examples using user-defiend types. You can certainly do odd things with C++ to get a related effect, for your own types. You can have a type "num" with a division operator that returns a "deferred_division" type encapsulating the numerator and denominator, with conversions to float, integer (and rational if you like) which do the actual division. There is a name for that pattern, which I have completely forgotten, and it can be useful in some types of coding. > > AFAIK the main criterion for "weird" is familiarity: C is widely > used and several languages ape some aspects of C. But for > uninitiated many things in C look weird (including your > division example). >
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-20 11:15 +0000
Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-20 13:49 +0100
Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-20 12:56 +0000
Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-20 15:36 +0100
Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-21 01:48 +0000
Re: How to disambiguate macro? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-07-20 19:18 -0700
Re: How to disambiguate macro? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-20 20:27 -0700
Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-21 04:15 +0000
Re: How to disambiguate macro? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-21 02:00 -0700
Re: How to disambiguate macro? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-21 06:02 -0400
Re: How to disambiguate macro? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-21 06:00 -0400
Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-21 10:10 +0000
Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-21 11:30 +0100
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-21 13:31 +0200
Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-21 13:02 +0100
Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-21 14:20 +0100
Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-21 15:15 +0100
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-21 16:28 +0200
Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-21 16:20 +0100
Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-21 17:34 +0100
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-21 19:46 +0200
Re: How to disambiguate macro? Manfred <noname@add.invalid> - 2021-07-21 20:42 +0200
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-22 08:37 +0200
Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-21 20:47 +0100
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-22 08:47 +0200
Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-22 11:31 +0100
Re: How to disambiguate macro? antispam@math.uni.wroc.pl - 2021-07-22 14:37 +0000
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-22 18:15 +0200
Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-21 21:19 +0100
Re: How to disambiguate macro? Manfred <noname@add.invalid> - 2021-07-21 15:42 +0200
Re: How to disambiguate macro? scott@slp53.sl.home (Scott Lurndal) - 2021-07-21 15:39 +0000
Re: How to disambiguate macro? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-07-21 09:22 -0700
Re: How to disambiguate macro? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-21 17:24 -0400
Re: How to disambiguate macro? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-07-21 16:42 -0700
Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-22 05:49 +0000
Re: How to disambiguate macro? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-07-22 19:11 -0400
Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-22 05:30 +0000
Re: How to disambiguate macro? scott@slp53.sl.home (Scott Lurndal) - 2021-07-22 14:14 +0000
Re: How to disambiguate macro? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-07-22 17:06 +0100
OT: possessive adjectives (Was: How to disambiguate macro?) Manfred <noname@add.invalid> - 2021-07-22 15:04 +0200
Re: OT: possessive adjectives Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-08-14 13:37 -0700
Re: How to disambiguate macro? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-08-14 13:58 -0700
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-20 14:50 +0200
Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-20 13:19 +0000
Re: How to disambiguate macro? Bart <bc@freeuk.com> - 2021-07-20 14:40 +0100
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-20 21:02 +0200
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-20 21:00 +0200
Re: How to disambiguate macro? David Brown <david.brown@hesbynett.no> - 2021-07-21 08:15 +0200
Re: How to disambiguate macro? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-08-14 23:17 -0700
Re: How to disambiguate macro? John Forkosh <forkosh@panix.com> - 2021-07-20 12:51 +0000
Re: How to disambiguate macro? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-07-20 08:47 -0700
csiph-web