[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: 1740562833781752.png (668 KB, 3752x2221)
668 KB
668 KB PNG
>>
run gcc -E on your C code and see what __thread turns into
>>
why should I, a nocoder, deal with manual memory management? why not Go?
>>
At least make it kind of a fair comparison.
>t. cnile
>>
>>106527347
i did when i was a teenager 20 years ago. no need for low level languages anymore, they are obsolete
>>
what a bloatfest. do none of the rust people care about thread local performance??

>>106527398
you can't mutate DATA without using interior mutability (like Cell<u32>)
>>
>>106527423
Oh, that's retarded. Why did they design it like this?
>>
>>106527444
The borrow checker can't reason about global or thread local mutable state, so you have to circumvent it basically. For most complicated types you'd use RefCell<T> which is basically moves the borrow checking (at most 1 mutable borrow NAND any number of immutable borrows) to runtime, but since u32 is a trivial Copy type, you can just reassign it every time you want to change it, and Cell<T> is what you use for that.
>>
File: hello.png (278 KB, 1282x680)
278 KB
278 KB PNG
I'm on it.
https://www.youtube.com/watch?v=HjXBXBgfKyk
>>
>>106527512
Lame. Apparently doing a bad and using unsafe isn't any better either.
>>
File: 1599873007318.png (117 KB, 372x351)
117 KB
117 KB PNG
>>106527398
>>106527654
>Rust programmers trying to write "Hello World"
>>
>>106527675
I literally said I'm not a rust programmer, and I don't want to be one.
>>
>>106527682
"real" rust programmers wouldn't have used unsafe like I did anyway. They'd have added 50 dependencies instead.
>>
>>106527512
The more I learn about the Rust internals, the less I’m impressed.
>>
>>106527544
porcoddio fra lo uso anche io sto canale
sto anche leggendo il libro ansi c second edition
>>
>>106527347
This exercise is kicking my ass bros.

>Write a program to check a C program for rudimentary syntax errors like unmatched parentheses, brackets and braces. Don't forget about quotes, both single and double, escape sequences, and comments. (This program is hard if you do it in full generality.)

I've got the basics down, but the full generality part is kinda kicking my ass (recognizing escape sequences, for example). What corner cases do you think it's referring to?
>>
>>106527757
Probably ignoring brackets inside of strings and comments, and escaped end quote characters? Don't forget about single line comments being extended with a backslash.

// comment \
this is also part of the comment
>>
>>106527757
so basically you just need to write a lexor, either that or a state machine

what's the problem?
>>
>>106527347
Why not just use a stack allocated variable? Unless you need a huge amount of space, you only pay the cost once for a bulk operation?
>>
>>106527830
Because sometimes you really do need per-thread globals, ie if you're making a library that needs per-thread storage for performance or correctness reasons and you don't want to or can't make your API users keep track of it. Malloc implementations are a good example of this, the malloc() function doesn't have any context parameter that you could give a thread ID to, but all good malloc implementations have per-thread arenas for smaller allocations.
>>
>>106527782
>Probably ignoring brackets inside of strings and comments, and escaped end quote characters?
I got that down
>single line comments being extended with a backslash.
Isn't that a C99 thing? I'm writing ANSI C. I detect comments by looking at the current character to see if it's * and checking if the previous character was a /. Then there's the inverse for checking when you exit the comment. It supports multi line but only in that format

I also implemented telling the user where the syntax error was in (line,column) coordinates, because I think it's stupid to just tell them there's an error instead of where exactly it is.
Output example:
Ya dun fuck'd up. C comments don't nest. @ (2, 1)
Ya dun fuck'd up. C comments don't nest. @ (3, 47)
Ya dun fuck'd up. C comments don't nest. @ (4, 47)
Ya dun fuck'd up. Comment ended without starting. @ (5, 43)
Ya dun fuck'd up. C comments don't nest. @ (11, 1)
Ya dun fuck'd up. Parens closed but never opened. @ (16, 4)
Ya dun fuck'd up. Parens opened but never closed. @ (18, 4)
Ya dun fuck'd up. Parens opened but never closed. @ (18, 3)
Ya dun fuck'd up. Bracket opened but never closed. @ (20, 1)
Ya dun fuck'd up. Brace opened but never closed. @ (19, 1)

This was tricky however because there is no limit to how many parentheses the user might want to nest, so being able to match a ( with a ) in a sea of thousands of them isn't trivial. So I i implemented a failsafe where if the file being fed to the program detects more than X open parentheses at any given time, it gives up on the coordinates and resorts to more simple reporting.

>>106527799
Me dumb.
>>
>>106527965
Did you catch string literals that span multiple lines?

char msg[] = "yadda yadda \
yadda yadda yadda ya";
>>
>2025
>nocoders still seething over rust
lmao
>>
>>106528059
Leave them alone, they actually have an excuse to be jobless this time...
>>
>>106528059
Im a senior coder and I dont even think about rust. shitty language
>>
>>106528059
the only time I think about rust is when I’m in a thread about C and some shitposter comes in seething about no memory safety or ‘cniles’ or some shit
>>
>>106527999
I did! If no closing double quotes are detected in the line they started in, and a newline is at the end, and the character just before that was '\', then it doesn't yell at you yet. The check is repeated for the next line until it either finds the closing double quote or yells at you.
>>
75 IQ nocoder here, why should i learn C when python makes things just work? Babbling about gay nerdy shit is not allowed.
>>
>>106528225
I don't care what language you learn. Just learn a language. A for loop is a for loop is a for loop. The greatest barrier to learning how to make cool shit on a computer is starting. The basic concepts are transferable skills to other languages.
>>
File: FunnyFrijole.jpg (35 KB, 600x600)
35 KB
35 KB JPG
>>106527347
>Learn C.
Y?
>>
>>106528225
I can only imagine how great computing would have been if we hadn't sacrificed every hardware gain we made for worse and worse software engineers...
>>
>>106527347
No, my time is more valuable than the computer's time.
>>
File: part_of_the_problem.png (363 KB, 828x683)
363 KB
363 KB PNG
>>106529107
"People" like you are why modern software is shit.
>>
>>106527384
then use Go
>>
>>106527347
I would like to but in the short term Python is going to pay better for me I think.
>>
That C code is UB, good job.
>>
File: ansic.png (256 KB, 897x1161)
256 KB
256 KB PNG
>>106529219
The only thing undefined is your knowledge of the C standard.
>>
>>106527347
I already learned C# and that's like 4 times better than just C, so I don't think I will.
>>
>>106529272
Basic floating point arithmetic is an order of magnitude slower in C# than C. C# is dogshit and only used by Jeets for webapps.
>>
>>106528084
there are no rust jobs anon
>>
>>106529256
I suspected as much but you're right.
>>
>it's this thread again
cniles just can't stop lying

>>106527398
>>106527654
are you retarded? why would writing it to a local variable first do anything else? what do you think the difference between cell and unsafecell is?
>>
>>106529394
Ah yes, why would you ever want to write to a variable anyway?
>>
>>106529439
what do you mean? you can set it just fine.
>>
>>106527347

Uninitialised variable. Already an UB in just two lines.

No proper context.

kys retard
>>
>>106529298
Bro it's got 4 more plusses than just regular C, so it's like 4 times faster. You're just jelly
>>
>>106529462
Globals are zero-initialized.
>>106529451
So for Rust to get equivalent assembly to C, you have to use an obscure compiler option that isn't enabled by default anywhere, the thread local cannot be public, and it has to be initialized with a const block. BTW, none of this would've been obvious without looking at the assembly which 99% of devs aren't going to do, so they'd forget one or more of those things and get worse code.
>>
>>106529540
>you have to use an obscure compiler option
dumb retard, clang/gcc don't generate position independent code by default, rust does
>the thread local cannot be public
my bad, I don't usually code in C so I forgot about that
>and it has to be initialized with a const block
it doesn't have to be. Rust's thread_local! allows for lazy initialization. read the documentation before using something.
https://doc.rust-lang.org/stable/std/macro.thread_local.html
>>
>>106529554
>you have to link your rust program against libc to compete with C
the absolute state lmao
>>
>>106529554
>clang/gcc don't generate position independent code by default, rust does
But you still get optimal assembly with -pie, which is all you need for ASLR.
>>
>>106529572
Yes. Everything uses libc. It is a sorry state of affairs but libc is the standard interface to every platform anyone is using. Yes even on Linux despite Linus retardedly keeping the kernel ABI stable.
>>
>>106529189
So why don't they have operating systems that just boot up almost instantly now that we have such fast and multi core CPUs?
Shouldn't I be able to push the power button and see a command line pop up on my monitor like flipping a light switch?
>>
>>106529603
I'll give your toy language a try when it no longer needs piggyback rides from C
until then cope seethe and dilate
>>
>>106527347
What will I do with C once I have learned it?
>>
>>106529829
write programs of coSegmentation fault (core dumped)
>>
>>106529829
learn D, E, F, and all the way down to Z
>>
>>106529202
Also in the long term
>>
>>106529632
It will happen soon, as more and more components of major operating systems get re-implemented in Rust.
>>
>>106529829
Make posts telling other people to use C. Like a lintard does in an OS thread, or a Rustroon in a language thread.
>>
>>106527417
What programming language would be a good choice for a 30-year-old hobbyist with no prior coding experience?
>>
>>106530294
C#
>>
>>106530294
Python probably.
>>
>>106530301
I do appreciate you, Anon. Thank you.
>>
>>106530306
dynamic typing encourages bad practices for beginner
>>
>>106530317
He's a hobbyist. He just wants to get stuff done, he doesn't need to care about that.
>>
>>106530327
non sequitur
>>
>muh typing matters
It literally fucking doesn't, even in Python you are well aware of types even if you don't need to autistically type them every single time you want to declare something, when I learned java after several years of exclusive python coding it came naturally and I had no issues adjusting at all

This shit about static vs dynamic typing is only something midwit dunning kruger redditards bring up seriously in a discussion
>>
>>106530294
a scripting language

I recommend Lua because it is small and simple and if you know a game that uses it, you can get quick and easy hits of instant gratification dopamine which is useful when you're first starting out.
>>
>>106530398
strong typing eliminates many different classes of bugs

>autistically type them every single time you want to declare something
that's mostly just a C problem because the language is old. C++ has auto and modern C memelangs have implicit type assignment with := while keeping all of the benefits of strong typing.
>>
>>106530398
midwit dunning kruger redditard
>>
>>106530398
Static typing is like the only thing in programming that we can say is 100% good all of the time after the field has developed for 80 years. You can't write robust non-trivial software with dynamic typing.
With every single massive refactoring I do in my code, all I can think is "God, this would be hell without types."
>>
>>106530209
>two more weeks
lmao
>>
>>106530427
>Static typing is
>100% good all of the time
not in fotw llvm frontends
all that u8 i32 etc. do nothing but distract the reader
>>
>>106530443
You can argue that sometimes it's better to have more general types that can hold more things and fewer very specific types.
I know Rust people think the opposite of that and that every invariant in your program should be encoded in the type system ("Make invalid states unrepresentable", a fool's errand btw) but I don't really ascribe to that. At some points it just turns into busy work with very little benefit.
I've indeed found cases where that simplifies the code, but that's something that the programmer should decide depending on what is appropriate for their use cases. The language itself must support static typing or it's not a serious language.
>>
>>106529829
Make something cool in raylib
>>
>c has to use obscure compiler flags for safety
>rust has to use obscure compiler flags to generate the code you actually want
KEK
>>
>>106530753
>rust has to use obscure compiler flags to generate the code you actually want
wrong, see >>106529554
>>
>>106530758
>PIC
nobody cares except rusttroons, this is a one time cost and a 0 time cost if you don't use shared libraries.
Rust of course must use this or their programs would be even more hilariously memory hungry cause they can't seem to write any software without pulling in 1000 crates
This is actually harmful in embedded btw
>>
>>106530788
none of what you wrote make any sense.
>>
>>106530795
How is it difficult to understand? You're code is only comparable to c when PIC and that isn't representative of requirements
>>
>>106530801
What are you even talking about? How is it so difficult to understand that Rust compiles with PIC by default on some targets and clang/gcc doesn't?
>>
>>106530813
Look at the code in the OP without pic its 2 instructions. You have to turn off PIC to compete, hence more obscure compiler flags to get the same performance as c out of the box. Now read my post, shut up, and stop spreading misinformation.
>>
>>106530822
>why is the C version without PIC shorter than the Rust version with PIC
dumb retard
>>
>>106530813
>by default
so why don't you show us the rust code with PIC disabled to prove that it produces the same code?
>>
>>106527398
>unsafe
>look what they have to do to imitate even a fraction of our power
>>
>>106530863
dumb retard, it's here >>106529451
>>
>>106527544
Good morning saar
>>
>>106529632
literally every used language piggybacks on C.
also,
>>rust devs don't reimplement c utils
>lmao @ rust trannies piggybacking on c
>>rust devs reimplement c utils
>lmao @ rust trannies reinventing the wheel
which is it, cnile?
>>
>>106530294
Python and C are unironically all you will ever need in this world
>>
>>106531350
>{2nd worst language} and {worst language} are unironically all you will ever need in this world



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.