Live data from Hacker News

Cello – A library that brings higher level programming to C

libcello.org

111–120 of 158 posts

Re: Cello – A library that brings higher level programming to C

#112

Earlier quoted context omitted.

It's arguable that extensive use of macros and faux-dynamic-typing violate the ideology of C that makes it simple and predictable.

I'd remove the “faux”. Cello is dynamically typed.

Then you could say that just using void-pointers in C that C is also dynamically typed.

Re: Cello – A library that brings higher level programming to C

#113
As a superstitious C programmer, typedefing (void star) feels like walking on the cracks in the pavement, crossing the path of a black cat, walking under a ladder, or squeezing a lemon under the full moon to me. These kinds of tricks seem very clever at first but there always comes a point when they start to break down. I'd be leery about using union in 2017, but typedefing (void star) is like putting on your underpants outside your trousers, thinking you're superman and jumping out of a window thinking that you can fly.

Re: Cello – A library that brings higher level programming to C

#114
post #102

How about performance? As I understand, it uses fat pointers fat pointers and GC, so performance drop is expected. There are not many reasons to use C nowadays beside performance.

> There are not many reasons to use C nowadays beside performance.

portability? stable ABI? ... writing something in C make it easy for any other higher level language to link to it. That's why we're not done with C, at all ... it's basically the only serious language out there used to share code among every possible platform or language. Even C++ which is a bit safer in practice is harder to link.

I just wished C was a bit safer by default (arrays with bound checking,...)

Re: Cello – A library that brings higher level programming to C

#115
post #111

Isn't this something similar to vala ?

No not really. Vala has an own seperate transpiler that generates C code from Vala code. Cello uses the normal C preprocessor to generate C code.

Actually Vala generates GObject code, which fundamentally has its own "type system" and uses reference counting.

Re: Cello – A library that brings higher level programming to C

#117

Take a turd and roll it in sugar it's still a turd. To me C is obsolete and most people who have a "reason" to use C don't really have a real reason other than stupidity. C++ does everything that C does except only better. ;-)

I guess you should stop using software written in this obsolete language then.

Re: Cello – A library that brings higher level programming to C

#118
post #71

Earlier quoted context omitted.

> So, for example, you know if at offset 0xDEADBEEF there is are 8 bytes which are holding a number that you want to use, you can access that chunk of memory and use it however you want. And you can interpret it how it is appropriate for your use case, for example reading it into a string, or an int. Except these days with strict aliasing that's not true. If you access memory through a pointer of the wrong type, you'…

'Strict aliasing' is a dangerous optimisation that OpenBSD's gcc-local disables for a reason.

Not really that dangerous, I think it's more of an issue of having code written before strict aliasing rule.

Essentially, what strict aliasing rule requires is that user cannot go crazy casting pointers. Casting float pointer to int pointer is completely wrong. The exception is that it's completely safe to cast values to char pointer or void pointer (and back, but only to original type of a pointer). Objects of different types cannot use the same memory area.

What this usually affects is code that parses external data into a structure. This can be dealt with by use of `memcpy` (to copy data from char array into a structure) instead of pointer casts, which is mostly safe as far C specification is concerned (mostly because C specification doesn't really define stuff like paddings, so you need to be careful about that). There is also an option of using `union` which is allowed by C11 specification (but compilers released with C11 that had strict aliasing optimization didn't break code that had aliasing through union and even documented that).

Re: Cello – A library that brings higher level programming to C

#119
Cool. This is a bit extreme but on purpose I think, it is an exploratory project AFAIK. If I had my hands free I would spend my time writing a new C library since I firmly believe that the problems of C are, for the larger part, in its standard library and not in the language itself. C memory model is unsafe but if mediated by a sane library for strings, and if by default you have most of the things where bugs are put (data structures, facilities for parsing, ...) things get a lot simpler and safer.

Re: Cello – A library that brings higher level programming to C

#120

Earlier quoted context omitted.

C++ isn't strictly a superset of C! Which I always found crazy. Some C will not compile for C++.

Can you provide C code that will not compile with c++ compiler?

Compound literals are outside of C++ standard. However GCC for example supports them, but a bit differently [0].

  $ cat foobar.c
  #include 
  
  struct foo {
  	int x;
  	int y;
  };
  
  int foobar(struct foo *f)
  {
  	return f->x + f->y;
  }
  
  int
  main(int argc, char *argv[]) {
  	(void)argc; (void)argv;
  
  	printf("%d\n", foobar(&(struct foo){10, 20}));
  	return 0;
  }
  $ gcc -Wall -Wcast-align -Wextra -pedantic -std=c99 foobar.c -o foobar && ./foobar
  30
  $ g++ -Wall -Wcast-align -Wextra -pedantic foobar.c -o foobar && ./foobar
  foobar.c: In function ‘int main(int, char**)’:
  foobar.c:17: warning: ISO C++ forbids compound-literals
  foobar.c:17: warning: taking address of temporary
  30
  $ # taking address of temporary means that it's undefined behavior
[0] https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html
Post reply on HN