r/linux • • Aug 16 '14

Yet another C object model

https://phab.enlightenment.org/phame/live/1//post/yet_another_c_object_model_but_better/
53 Upvotes

60 comments sorted by

View all comments

0

u/[deleted] Aug 16 '14

[deleted] — view deleted comment

12

u/tidux Aug 16 '14

That's like saying "My Model T needs a jet engine and wings." At that point it's not a Model T anymore.

7

u/pushme2 Aug 16 '14

I would agree. One of the defining characteristics of C is that you can do whatever you want for the most part and it will probably work. Changing any of those things would mean that it wouldn't be C.

If you agree that those things are good and want to try them, there is always rust.

0

u/[deleted] Aug 16 '14

[deleted] — view deleted comment

12

u/[deleted] Aug 16 '14

Saying C needs "Multiplatform support built-in" shows you clearly don't understand what C is or how it works.

4

u/azalynx Aug 16 '14

The clang devs are working with the C/C++ standards groups on a proposal for "modules". They will essentially be a sort of standardized way to do precompiled headers, without the issues that precompiled headers currently have.

There's also a talk about this subject on youtube.

0

u/[deleted] Aug 17 '14

[deleted] — view deleted comment

1

u/azalynx Aug 17 '14

As some others have noted or implied, it seems that you just want C (and/or C++) to become a high level language.

The reason their approach is a "practical one" is because it's the most elegant approach that maintains compatibility with headers in a reasonable way, while still providing the most desired aspects of modules, and reducing compile times (especially for C++ as I understand that in C++ a lot of code exists in headers which bloats up compile times significantly).

Furthermore, their proposal accomplishes these goals without changing the nature or purpose of the C language as a low level systems implementation language. Or C++'s purpose as "C with some high level sugar".

Anything that changes the language too drastically or radically will not be adopted. Nor will anything that can already be done by compilers, IDEs, lint checkers, and other tools, as that just makes those features out of scope.

8

u/[deleted] Aug 16 '14

Then go and use something trendy. Objective-C? Swift? Ruby? Clumsy C++? Rust? Pick your poison.
I don't believe any FOSS developer uses C because it's nice but because we like it and it gets things done.

Type safety

-Wall solves this. There's no reason not to use this flag.

Clear distinction between pointers and arrays.

Heck no. Absolutely not. Give me a good reason, and it better be a Shakespearian masterpiece.

Defer, to get rid of the massive amounts of gotos.

What's wrong with occasionally using gotos to handle failures?

Arrays and strings should have a length indicator and not zero terminated.

I could agree for strings. I disagree for arrays.

Bounds checks of arrays.

Most compilers already do for static arrays, which is the only place possible.

Modules with namespaces so that the macro crap doesn't have global scope, you have sane data hiding and can get rid of the header files that are being read multiple times during compilation. The header files could be replaced with interface files.

Why? I like macros. They are a nice, robust way of getting things compiling the way you want them to. What's the point of hiding macros? That's unnecessary. And I absolutely, unequivocally hate the C++ shit of having your entire code in classes in headers. Fuck no, I like my .h + .c file combo any day of the week all week.

Multiplatform support built-in to get rid of the #ifdef hack (most of them).

For what purpose? Ifdef is not a hacky way of doing multiplatform stuff, it's the one and only. Considering most of the multiplatform shenanigans come from different definitions of functions it's the right tool for the job, if a bit ugly.

2

u/zem Aug 17 '14

parent is absolutely right about macro scoping. the point is not to hide them, the point is to have better and more explicit control over what macros are active where, so that you never have to worry about someone's globally imported macro definitions conflicting with yours. the current mess with #undef is a clumsy hack.

0

u/[deleted] Aug 16 '14

[deleted] — view deleted comment

2

u/Alborak Aug 16 '14

If you want bounds checking on arrays do it yourself. Not going off into space when working with arrays is not hard. I dont need bounds checking in my bootstrap code, I know exactly where my stuff is going. That's one of the best the best parts of c, when you know what you're doing the language won't get in your way.

2

u/rastermon Aug 16 '14

Indeed. That's why we love it. All we needed was some extra infra and features and again the language didn't stop us. We just had to do the footwork. We made it a lib to reuse and share. Well build tools too.

→ More replies (2)

4

u/[deleted] Aug 16 '14

...ifdefs...

I disagree.

You barbaric...

It is because bounds checks should also work for malloc'ed arrays.

...bastard. It's been decided. We fight. 1vs1. Quake 3 DM. 15 min/15 kills. Random map. Name the time, the server and I'll be there.
Arrays should be only a simple, virtually uniform region of memory, filled with nothing but what you put in them, every sizeof(variable). Want to get a member != to the first? Offset array start pointer by n*sizeof(variable).
Suspect you go over the bounds? Print the index somehow. Otherwise wait for a segfault. GDB that stuff and fix your problem by making sure it won't happen. Doing a check every single time you access an array is absolutely not something I want my CPU cycles spent on. You learn to ride a bike by crashing, damnit.

0

u/[deleted] Aug 16 '14

[deleted] — view deleted comment

4

u/rowboat__cop Aug 16 '14 edited Aug 16 '14

Are you the developer of Heartbleed btw?

Bounds checks wouldn’t have eliminated Heartbleed: All the memory was allocated correctly and no out-of-bounds access ever took place.

If you can show your arrays are NUL/NULL terminated or the index falls within the array bounds anyways then a bounds check shouldn’t be required at all. What C needs is a framework to prove that this is the case, and a compiler that will refute your assumptions prior to runtime. Basically, something like ATS is the way to go if we intend to stay true to C’s values, not mandatory bounds checking. (Optional checking could help to some extent, though, especially in cases where you’d usually rely on manual checking.)

→ More replies (4)

2

u/rastermon Aug 16 '14

If it didn't need it we worksheets wouldn't have done it. Most of v what you mention c needing we have little to no need of. We rarely use arrays and when we do access safety is not an issue. Objects are though.

2

u/rastermon Aug 16 '14

Dang autocorrect

1

u/nialv7 Aug 16 '14 edited Aug 16 '14

As for defer, if you are using gcc, you could use:

__attribute__((cleanup(cleanup_function)))

1

u/Beckneard Aug 16 '14
  • yep
  • nope, the overhead would make the language useless for a lot of purposes (low level stuff like embedded, kernel programming etc.).
  • why?
  • nope, see no. 2
  • yeah proper type safety would be nice
  • not sure what you mean by that
  • maybe, it's fine for the most part
  • I really don't see how that would be possible for all cases, you do realize C isn't supposed to have a super huge all purpose standard library like, say, Python has? The relatively little it has is completely cross platform.

1

u/tubal_cain Aug 16 '14

If you have these specific requirements in mind, why not just take the path of least resistance and use C++? Instead of asking for C to be extended with 1/2 of C++'s feature-set, you might as well use the whole thing and take advantage of resource management via RAII, more type-safety, templates as an alternative meta-programming facility (aside from macros), smart pointers with well-defined ownership semantics, and std::array for type-safe arrays.