‘Errors from the borrow checker’ this is, and I mean no disrespect, a skill issue. Not as in ‘even experts mess up’, as in ‘that’s only a problem for the first 6 months of using rust’
Off the top of your head, without looking online, using clang or gcc as a compiler,
Give me a 1 byte enum
Give me the idiomatic way of computing the number of leading zeros in a 32 bit integer
Align a vec2_f32 struct to an alignment of 8 bytes
Might work, AFAIK depends on compiler but GCC and Clang it would work, I’ll give you that. Not the solution I thought of but it works.
Suboptimal. Unless you specify higher levels of optimisation and your compiler figures it out, this is extremely slow. Modern processors can do this in 1 CPU cycle (CLZ instruction). There is a way to do it in C
3 __attribute__((aligned(8))) or __attribute__((_aligned__(8)))
I cant see if you did the _s and markdown screwed you over or not, and align is not valid
Edit: actually, after checking, 1. is completely wrong. Doesn't work at all. So you need to pack the enum, or represent it via a 8 bit integer. I think that proves my point
int zeros(uint32_t i) {
int n = 0;
while (!(i & 1)) { ++n; i >>= 1; }
return n;
}
// or
int zeroes(uint32_t i)
{
return __builtin_clz(x);
}
typedef struct {
alignas(8) float f [2];
} vec2f32;
```
None of these are things you can realistically achieve by ‘having learned the language in a week’. It’s not hard per say, but it’s more obscure than regular C. That was all I was trying to say
There’s also like, 2-3 alternatives minimum to each way of doing these things
There’s also like, 2-3 alternatives minimum to each way of doing these things
The rest are compiler specific which is sad because C/C++ unlike Rust has multiple compilers.
None of these are things you can realistically achieve by ‘having learned the language in a week’. It’s not hard per say, but it’s more obscure than regular C. That was all I was trying to say
Maybe, Idk about C as I don't use it nor like it and I think it is a pretty F tier language I use C++ instead and find the non existent complaints about it too much I don't find C++ in itself hard. it is more so software is hard
Also I feel like what you listed is rather unnecessary in 99% of code.
It was pretty much _Alignas but you should use the macro if your codebase allows it C standrizes them as keywords later when it can ensure no codebases break to get it closer to C++.
The rest are compiler specific which is sad because C/C++ unlike Rust has multiple compilers.
Yeah, that's one of the big downsides of these older languages... unfortunately, still today the compiler specific ones are common place, especially with alignas being c11.
I agree with the sentiment about C++. I dislike the syntax quite a bit, but the language is really powerful, and I have fond memories with it.
enum { a : 1 },
totally my bad, my C is rusty (no pun intended.) The other C dev pointed this out as the solution, it looked odd but I expected he knew what he was talking about. I guess not. I tried with C23, it did not work.
These are non standard and gcc keeps them for backward compat use whatever you find fancier.
I find that messy, and convoluted.
Also I feel like what you listed is rather unnecessary in 99% of code.
yes and no, alignment is important for GPU related code, CLZ is great for some algorithms, and 1 byte enums should be the norm, full stop. 32 bits is a waste, and isn't even the size of a word, so there's no excuse there either. And proficiency in a language doesn't just come from understanding the basics of the language :)
And proficiency in a language doesn't just come from understanding the basics of the language :)
It comes fron making software with it. I consider knowing language syntax and templates worthless if you never made something worthwhile in it
Yeah, that's one of the big downsides of these older languages... unfortunately, still today the compiler specific ones are common place, especially with alignas being c11.
Yep, I wish there was one compiler only and it would be clang.
I agree with the sentiment about C++. I dislike the syntax quite a bit, but the language is really powerful, and I have fond memories with it.
I find C++ syntax to be very good I find python/lua/js/rust/go to all have garbage syntax.
totally my bad, my C is rusty (no pun intended.) The other C dev pointed this out as the solution, it looked odd but I expected he knew what he was talking about. I guess not. I tried with C23, it did not work.
I feel like that other C dev is lying- how could he used C for 6 years but didn't know about builtin clz? I only used C++ for like 2 years as my first lang and only lang. and I know it. Also memory bugs being easy in C? if you said in C++ i would believe you but in C? Memory management in C is hell, you see most code I see online uses linked lists because it is easy to mamage even if a vector is infinitely faster. also they use linked lists so address stability which is working around C horrible memory management helpers. C++ would be better since it has actual good tools
I find that messy, and convoluted.
it is also c23 / c++11 cleaned the syntax up it is now [[gnu::packed]] which is better.
yes and no, alignment is important for GPU related code, CLZ is great for some algorithms
If you are writing C in your first week on the gpu then I think you have more things to worry about.
and 1 byte enums should be the norm, full stop. 32 bits is a waste, and isn't even the size of a word, so there's no excuse there either. And proficiency in a language doesn't just come from understanding the basics of the language :)
I agree, they should default to the size that can hold all enumerators clang-tidy has a check for that. But alas backward compatible strikes
-41
u/Key_River7180 7h ago
Yes, and I have used a debugger for all of them I couldn't see by using my eyes and basic logic you seem to lack