Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: What is "complexifying" C? |
| Date | 2015-03-17 11:09 -0700 |
| Organization | None to speak of |
| Message-ID | <87mw3bzeao.fsf@kst-u.example.com> (permalink) |
| References | <me7jgp$r9e$1@speranza.aioe.org> <me7mv4$hl9$1@dont-email.me> <87vbhzzmu3.fsf@kst-u.example.com> <me9g26$tb9$2@speranza.aioe.org> |
jacob navia <jacob@spamsink.net> writes:
> Le 17/03/2015 16:05, Keith Thompson a écrit :
>> If I define, for example, my own 96-bit unsigned integer type, how much
>> code do I have to write in C-with-overloading to make this legal?
>>
>> my_uint96 x = 42;
>
> You define the assignment operator with my_uint96 at the left side and
> int at the right side.
So an overloaded assignment operator applies to initialization as well?
And presumably to argument passing and return statements? That makes
sense, but I don't think you mentioned it (or I missed it).
Suppose an implementation of C+operator-overloading has a maximum size
of 64 bits for its predefined integer types. Then I can't write:
my_uint96 x = 79228162514264337593543950335; /* 2**96-1 */
unless there's a mechanism for user-defined literals. I'm not saying
that's a fatal flaw, it's just an observation.
But you snipped a second line of code:
x += 3;
Do we also have to explicitly overload "+" for a left operand of
type my_uint96 and a right operand of type int?
For existing types, mixed-type arithmetic depends heavily on implicit
conversions, with moderately complex rules for when they occur.
Can I define an implicit conversion from int to my_uint96, or vice
versa? Can I define when that implicit conversion occurs? Can I
define an *explicit* conversion by overloading the cast operator?
Without user-defined implicit conversions, I'd either have to
define overloaded operators for my_uint96 <op> <type> and <type>
<op> my_uint96, for each operator and each existing integer type.
That would quickly become unwieldy. Or I'd have to ensure that
I don't mix my_uint96 with other types (which would require
user-defined explicit conversions).
Giving users the ability to define their own types that behave like
built-in integer types (and *maybe* redefining the predefined integer
types using the new mechanisms) would be a lot of work. Defining the
rules consistently might be harder than implementing them.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-16 22:55 +0100
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-16 22:55 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-16 16:41 -0700
Re: What is "complexifying" C? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-17 00:05 +0000
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-17 01:12 +0000
Re: What is "complexifying" C? Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-25 13:58 -0700
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 07:16 +0100
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-17 13:50 +0000
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 14:59 +0100
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 15:22 +0100
Re: What is "complexifying" C? David Brown <david.brown@hesbynett.no> - 2015-03-17 16:16 +0100
Re: What is "complexifying" C? Kaz Kylheku <kaz@kylheku.com> - 2015-03-17 14:39 +0000
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-17 15:23 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-18 15:40 -0700
Re: What is "complexifying" C? Kaz Kylheku <kaz@kylheku.com> - 2015-03-18 22:49 +0000
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-19 13:55 +0000
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-19 15:37 +0000
Re: What is "complexifying" C? jacob navia <jacob@jacob.remcomp.fr> - 2015-03-19 23:06 +0100
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-19 22:38 +0000
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-20 19:43 +1300
Re: What is "complexifying" C? jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 07:49 +0100
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 02:29 -0500
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-20 21:37 +1300
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 03:40 -0500
Re: What is "complexifying" C? David Brown <david.brown@hesbynett.no> - 2015-03-20 10:18 +0100
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-21 00:19 -0500
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-20 03:15 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-22 13:51 +1300
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-22 15:21 +1300
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-22 00:57 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-22 22:28 +1300
Re: What is "complexifying" C? fir <profesor.fir@gmail.com> - 2015-03-22 02:59 -0700
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-22 11:16 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 07:25 +1300
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-22 12:06 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 17:01 +1300
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-23 03:09 -0700
Re: What is "complexifying" C? fir <profesor.fir@gmail.com> - 2015-03-23 01:42 -0700
Re: What is "complexifying" C? Melzzzzz <mel@zzzzz.com> - 2015-03-22 19:32 +0100
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-22 17:34 -0500
Re: What is "complexifying" C? Richard Damon <Richard@Damon-Family.org> - 2015-03-22 20:07 -0400
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-23 00:00 -0500
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 18:04 +1300
Re: What is "complexifying" C? Richard Damon <Richard@Damon-Family.org> - 2015-03-23 23:22 -0400
Re: What is "complexifying" C? Richard Damon <Richard@Damon-Family.org> - 2015-03-22 14:54 -0400
Re: What is "complexifying" C? Melzzzzz <mel@zzzzz.com> - 2015-03-23 00:35 +0100
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 17:06 +1300
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 17:25 +1300
Re: What is "complexifying" C? Martin Shobe <martin.shobe@yahoo.com> - 2015-03-22 23:33 -0500
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-23 18:01 +1300
Re: What is "complexifying" C? James Kuyper <jameskuyper@verizon.net> - 2015-03-23 09:41 -0400
Re: What is "complexifying" C? James Kuyper <jameskuyper@verizon.net> - 2015-03-23 10:23 -0400
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-24 07:10 +1300
Re: What is "complexifying" C? James Kuyper <jameskuyper@verizon.net> - 2015-03-23 14:57 -0400
Re: What is "complexifying" C? David Brown <david.brown@hesbynett.no> - 2015-03-24 09:36 +0100
Re: What is "complexifying" C? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-24 08:42 +0000
Re: What is "complexifying" C? David Brown <david.brown@hesbynett.no> - 2015-03-24 11:23 +0100
Re: What is "complexifying" C? Richard Heathfield <rjh@cpax.org.uk> - 2015-03-24 10:52 +0000
Re: What is "complexifying" C? raltbos@xs4all.nl (Richard Bos) - 2015-03-29 16:58 +0000
Re: What is "complexifying" C? Melzzzzz <mel@zzzzz.com> - 2015-03-22 02:38 +0100
Re: What is "complexifying" C? Richard Damon <Richard@Damon-Family.org> - 2015-03-22 09:11 -0400
Re: What is "complexifying" C? Les Cargill <lcargill99@comcast.com> - 2015-03-20 06:30 -0500
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-20 10:31 +0000
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-20 13:49 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-20 09:23 -0700
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-21 08:28 +1300
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-20 01:04 -0700
Re: What is "complexifying" C? Keith Thompson <kst-u@mib.org> - 2015-03-17 08:05 -0700
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 16:08 +0100
Re: What is "complexifying" C? Keith Thompson <kst-u@mib.org> - 2015-03-17 11:09 -0700
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 21:37 +0100
Re: What is "complexifying" C? Robert Wessel <robertwessel2@yahoo.com> - 2015-03-18 00:40 -0500
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-17 15:34 +0000
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-17 15:06 +0000
Re: What is "complexifying" C? Melzzzzz <mel@zzzzz.com> - 2015-03-17 00:05 +0100
Re: What is "complexifying" C? Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-16 23:20 +0000
Re: What is "complexifying" C? Ian Collins <ian-news@hotmail.com> - 2015-03-17 16:42 +1300
Re: What is "complexifying" C? Mark Storkamp <mstorkamp@yahoo.com> - 2015-03-17 08:59 -0500
Re: What is "complexifying" C? jacob navia <jacob@spamsink.net> - 2015-03-17 15:18 +0100
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-17 14:41 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-18 15:47 -0700
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-19 00:26 +0000
Re: What is "complexifying" C? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-19 03:23 -0700
Re: What is "complexifying" C? Bartc <bc@freeuk.com> - 2015-03-19 11:19 +0000
csiph-web