|
|
Subscribe / Log in / New account

Comparison to Go?

Comparison to Go?

Posted Jan 6, 2025 12:39 UTC (Mon) by rweikusat2 (subscriber, #117920)
In reply to: Comparison to Go? by dvdeug
Parent article: Preventing data races with Pony

>>> code which shouldn't compile does anyway because C doesn't care whether it's sensible to add (for example) a
>> bool to a float or a character to a pointer

>> C has no character type

> C has a type named char that is guaranteed to hold a character, [...] written in the source code as 'a'.

As I wrote in the part of my text you've chosen to ignore: char is an integer type guaranteed to be large enough for the codepoint of any character in the so-called basic execution character set and 'a' is literal of type int whose value is the codepoint of the character a in the character set (encoding) that's being used, usually 65 for ASCII.

>> [...] "add a character to a pointer" in C and equally impossible to "add a boot to a float".

>>void f (void *p) {
>>float pi = 3.14;
>>p += 'a';
>>pi += 0 < 1;
>}
>
>compiles without warnings on GCC -Wall. That just proves the post you're responding to; C doesn't care whether it's >sensible to add 'a' to a pointer, and arguing that 'a' is just a fancy way to write an integer in C and isn't a character is >silly.

"Silly" is value judgement of yours which doesn't change the C language definition where 'a' is (see above) an integer literal of type int and < is defined as having a result of type int which is 1 if the relation is true and 0 otherwise.


to post comments

Comparison to Go?

Posted Jan 6, 2025 17:47 UTC (Mon) by rweikusat2 (subscriber, #117920) [Link]

ASCII codepoint of 'a' is 97 and not 65, that's 'A'.

General property of ASCII that's sometimes useful: The difference between an uppercase letter and the corresponding lowercase latter is that the 6th bit (32) is set for the latter and clear for the former.

Comparison to Go?

Posted Jan 6, 2025 18:04 UTC (Mon) by dvdeug (guest, #10998) [Link] (4 responses)

Going back to the original complaint:
> C doesn't care whether it's sensible to add (for example) a bool to a float or a character to a pointer,

The fact that the C standard calls char an integer type is why C doesn't care. It doesn't change the fact you're adding a character to a pointer, it just means that C doesn't see it that way.

You wrote
> "Silly" is value judgement of yours

Yes.

>which doesn't change the C language definition

Which is irrelevant. If you claimed that Ada generics aren't powerful, could I point out the Ada language definition says "Finally, the language provides a powerful means of parameterization of program units, called generic program units" and claim victory? If someone is arguing that C's type system is deficient because it lets you add a bool to a float, it doesn't help to point out that C just treats bools as integers.

Comparison to Go?

Posted Jan 6, 2025 19:05 UTC (Mon) by rweikusat2 (subscriber, #117920) [Link] (3 responses)

>> C doesn't care whether it's sensible to add (for example) a bool to a float or a character to a pointer,
> The fact that the C standard calls char an integer type is why C doesn't care. It doesn't change the fact you're
> adding a character to a pointer, it just means that C doesn't see it that way.

There is no such thing as a character type in C and hence, there's no way to add a character to anything in C. That's a fact which is part of the language definition.

> If someone is arguing that C's type system is deficient because it lets you add a bool to a float, it doesn't help to
> point out that C just treats bools as integers.

Likewise, there is no such things as a bool type in C that's distinct from an integer type and hence, adding a bool to a float is also something that's impossible in C. That's also part of the C language definition. It's obviously possible to argue that the C type system should really contain concepts like character or boolean types but as a matter of fact, it doesn't. Hence, this particular criticism is disingenuous. C allows addition of numbers and due to the relative paucity of the type system, numbers are also employed to represent entities (like characters or boolean values) which have types of their own in other programming languages. But that's strictly a matter of interpretation. 97 is an integer. In certain contexts, it might represent the character a and in others, it doesn't.

Comparison to Go?

Posted Jan 6, 2025 19:34 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link] (1 responses)

> There is no such thing as a character type

What is a "character type"?

Comparison to Go?

Posted Jan 6, 2025 19:46 UTC (Mon) by adobriyan (subscriber, #30858) [Link]

This whole confusion is because "character constant" token doesn't have type "char" in C.

"char" of course officially exists now: _Generic dispatches on "char" as it does on "_Bool".
Informally, BTCP recognised "char" as real type for quite some time.

Comparison to Go?

Posted Jan 7, 2025 4:41 UTC (Tue) by dvdeug (guest, #10998) [Link]

I once heard that someone claim that many older programming languages were named for what they process, like LISP for lists, FORTRAN for formulas, SNOBOL for strings, and C for characters. Jokes aside, a whole lot of early code written in C was for character processing; a C compiler, sed, ed, vi, awk, half the programs in GNU Coreutils.

> There is no such thing as a character type in C and hence, there's no way to add a character to anything in C.
...
> It's obviously possible to argue that the C type system should really contain concepts like character or boolean types but as a matter of fact, it doesn't. Hence, this particular criticism is disingenuous.

No, this particular criticism is not disingenuous. What's disingenuous is when you take a language that has built-in features to handle character data and a type designed to hold character data (named char) and character constants, where you can take a pointer p and add 'a' to it, and act like criticizing that is unreasonable because the text of the standard doesn't have a character type.

Oh, and C11 ยง6.2.5.15 says "The three types char, signed char, and unsigned char are collectively called the character types." I don't have access to all the C standards documents, but at least that one officially says it has character types. So not only is your claim trying to use pedantry to avoid reality, it's using pedantry that's not correct.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds