Readit News logoReadit News
dmux · 4 months ago
>Disclaimer: This library is not related to the MISRA C standard or guidelines. The name "MisraStdC" comes from the author's name, Siddharth Mishra, who is commonly known as "Misra" among friends.

Why include the letters Std then? This seems like a purposeful typo-squatting effort and definitely makes me suspicious.

donperignon · 4 months ago
Wow! Thanks for pointing that out, so misleading…
brightprogramer · 4 months ago
yep, glad you pointed that out. To explain a bit more : MisraStdC is 3 parts : Misra + Std + C - Misra is derived from my name. That's why I needed to specify that the repo is not related to the MISRA standard.
brightprogramer · 4 months ago
because it's my personal standard. I use it more than I use standard C utils.
CyberDildonics · 4 months ago
Did you really take the name mishra and make it into misra.h then call your library MisraStdC and expect people to believe the confusion isn't intentional? This whole thing feels incredibly dishonest.
teo_zero · 4 months ago
> A modern C11 library

I'd say "mostly C11": it uses __VA_OPT__ that's been standardized only in C23.

The "foreach" macros need a lot of refinement: passing the body in the parameters is asking for troubles, for example. And using a non-unique default name for the index prevents nested loops.

To overcome the issues with generic and qualified types, have you considered using typeof_unqual?

  _Generic(*(typeof_unqual(x)*)0, ...)

brightprogramer · 4 months ago
Yea the FMT trick uses VA_OPT. I consider myself a noob with C official specification, so you're probably right about that.

I do kinda like how foreach is implemented right now. This allows me to perform some strict checking for easy loop iteration based bugs and also it kinda looks cool.

This is the first time I came across typeof_unqual. I'll look into it, thanks .

I spent a lot of time making this work across all three compilers (especially MSVC). I'm glad MSVC has VA_OPT support.

teo_zero · 4 months ago
> I do kinda like how foreach is implemented right now. This allows me to perform some strict checking for easy loop iteration based bugs and also it kinda looks cool.

Yes but the body in the parameters really is a show stopper. What if the body has a unprotected comma? Like

  VecForeach(&v, e, {
    int x, y;
    ...
  });
Better to expand the macro into one or two "for" and let the body follow. For example:

  #define VecForeachIdx(v, var, idx)\
    for (size idx=0,_d=1; ValidateVec(v),_d; _d--)\
      for (VEC_DATATYPE(v) var={}; idx<(v)->length && (var=VecAt(v,idx),1); idx++)
Please note that I haven't tested it.

WalterBright · 4 months ago
> brightprogrammer

There can be only one.

yuppiemephisto · 4 months ago
That’s what I was thinking seeing the username =)
brightprogramer · 4 months ago
It's an honor to have you comment here .
WalterBright · 4 months ago
Thank you for the kind words!

Deleted Comment

brightprogramer · 4 months ago
been working on this for some time. has some usable features. i keep adding as i feel the need. try to well document everything and maintain it.
brightprogramer · 4 months ago
I especially am in love with how my formatted printer works. It's not a completely new solution and I think people have already done that. I'll also say that it's not very mature but it makes life a lot easier in some cases.

One example is me parsing HTTP headers: https://github.com/brightprogrammer/beam/blob/master/Source%...

teo_zero · 4 months ago
What disturbs me is the need to Init() everything. In the Vec type (the only one I've analyzed, actually) all it does is to fill everything with zeros and add a "magic" field certifying that the initialization happened. So why don't simply fill everything with zeros, which can be achieved with ={} if you're super modern or ={0} if you're not, and then drop the check for the magic field? Of course that wouldn't detect a missing intialization, but neither is it detected for any standard type.
brightprogramer · 4 months ago
It is a bit crazy but forcing this kinda makes a habit. That way, a habitual user will tend to initialize other variable types as well.

That's why I call it a standard, because the library has its own coding style. Take the ownership semantics explained in concepts section of README for example. I provide a way to very clearly specify ownership.

Also the init() instantly detects bugs related to uninitialized struts. When they do happen, sometimes very deep in the code they take a lot of time.

This is also one of the reasons why there are so many ValidateX checks in implementation code. Try to catch bugs faster.

Panzerschrek · 4 months ago
Why do people do such wired projects? Why not just using C++ instead of pure C?
dfawcus · 4 months ago
Maybe because one is working on a legacy C program, and for various reasons adding C++ to said program is too risky or expensive?
brightprogramer · 4 months ago
Because I just don't like it as much and I wanted to see how much farther can we go by just using macro tricks.
Panzerschrek · 4 months ago
Ok, it's fine, if you just wanted to experiment with macros. This seems to be a legit reason to use pure C.
brightprogramer · 4 months ago
It also compilers way faster than C++ code if that interests you :-)
Panzerschrek · 4 months ago
I agree, C++ code compilation is generally slower compared to C. But the compiler itself isn't particularity slower (under the hood it's the same compiler), but compiling C++ code with a lot of templates is slow.

For me personally compilation slowdown is just a price, which I am ready to pay for more language features, including better abstractions and type safety.

Deleted Comment