Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #58304

Re: What is "complexifying" C?

From Bartc <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: What is "complexifying" C?
Date 2015-03-17 14:41 +0000
Organization A noiseless patient Spider
Message-ID <me9ect$up8$1@dont-email.me> (permalink)
References <me7jgp$r9e$1@speranza.aioe.org> <mstorkamp-13E1AC.08590117032015@88-209-239-213.giganet.hu>

Show all headers | View raw


On 17/03/2015 13:59, Mark Storkamp wrote:
> In article <me7jgp$r9e$1@speranza.aioe.org>,
>   jacob navia <jacob@spamsink.net> wrote:
>
>> There are now following number types in C:
>>
>> 1) char (signed and unsigned)
>> 2) short (signed/unsigned)
>> 3) int (signed/unsigned)
>> 4) long (signed/unsigned)
>> 5) long long (signed/unsigned)
>>
>> That makes for 10 integer types
>> 11) float
>> 12) double
>> 13) long double
>> 14) float _Complex
>> 15) double _Complex
>> 16) long double _Complex
>>
>> That makes for 16 different types of numbers. In advanced
>> standardization process we have
>>
>> Decimal floats
>> Fixed point numbers
>>
>> We have many different types of floating extensions (with more
>> precision) or integer extensions (bignums) and a long list of possible
>> other types of numbers for different applications, like numbers defined
>> by an interval for easing error analysis, etc.
>>
>> Operator overloading SIMPLIFIES THE COMPILER AND THE LANGUAGE since it
>> proposes a SINGLE mechanism that would allow users to implement their
>> own number types without adding the enormous complexity of integrating
>> all those numbers into the compiler itself.
>>
>> The reasoning that operator overloading makes C more complex is wrong,
>> actually the opposite is the case. Adding specific types of numbers into
>> the language itself makes the implementations even *more* complex, and
>> forces decisions into the committee that should be actually left to the
>> users!
>
> Maybe I have a non-conforming compiler, but I have no problem with the
> following code without using operator overloading:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> long int add(long int a, long int b)
> {
>    return a+b;
> }
>
> int main(void)
> {
>    int a = 4;
>    char b = 3;
>    float result;
>
>    result = add(a, b);
>    printf("a+b=%f\n", result);
>    return EXIT_SUCCESS;
> }
>
> Granted I'm not introducing my own type of numbers, but the standard
> promotion rules seem to cover most of the issues one might have when
> mixing types of numbers.
>
> I've written my own set of routines for dealing with vectors, and I
> don't see how having operator overloading would have helped me much at
> all in implementing it. What operator would I overload for cross or dot
> product? What if I want to multiply a vector by the magnitude of another
> vector?

You'd probably use "*" for both:

  p = q * r;
  p = q * magnitude(r);

(The cross-product function implementing "*" would need to return a 
vector by value.)

They do have uses, in the right language. But the way you did it 
probably looks natural for a language such as C, and it would look odd 
for it to deal easily with vectors when it can't yet do anything much 
with strings.

Similarly, it would look odd in a scripting language designed to work 
with 3D geometry, to have to write code like this:

vector p, q, r;
vector temp1, temp2;
char str[256];

vecproduct (&temp1, q, r);
addvector (&temp2, p, &temp1);
mulvector_by_scalar (&temp2, &temp2, 0.5);
vector_to_str (str, sizeof(str), &temp2);
printf("(p+q*r)/2 = %s\n");

instead of just:

println (p+q*r)/2

Sure, it would be nice to have in C, but this easy, informal style 
doesn't sit well with the rest of language.

It would also be opening a can of worms. There would also be loads of 
overloads needed to fully implement this, intermediate values to worry 
about, memory management ... that would need more ideas to be copied 
from C++ to mop all the untidy aspects.

It would be easier to just use C++ and do it properly.

-- 
Bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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