[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]


Janitor applications are now being accepted. Click here to apply.


[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
>>
>>106527347
>You should learn this cool programming language
>Shows the most boilerplate hello world-esque code you could imagine
Might as well say "'learn mspaint'' and show us a blank canvas you drew a circle on

Why don't you make something interesting before you tell others what to do, fag
>>
File: it'sC.png (681 KB, 1334x750)
681 KB
681 KB PNG
>>106531066
finally you understand.
And btw rust will never escape that obscure utils hole, actual system will forever be in C
>>
>>106531701
pascal doesn't
>>
>>106527347
>C shitware so bad it has conditional code that waits for you to use pthreads before triggering a cascade of brand new behavior.
ok, kiddo.
>>
>>106531373
Your opinions are retarded. You're probably the hipster fag that recommends obscure dead on arrival Odin and dead end Lua in every thread. Find work, nigga.
>>
>>106531066
>rust devs reimplement c utils
poorly
>>
rec a good website/book/course, thank you.
>>
>>106532122
k&r chapter 1 and 2 and then off to writing actual programs and exploring contemporary compilers
>>
>>106527347
>>106527398
>>106527654
Wtf are you guys even doing?

>>106529632
You can use Rust in no-std mode and it will no longer depend on any libc. That's how you do embedded development in Rust anyway.
>>
File: 1698208685526365.jpg (23 KB, 640x559)
23 KB
23 KB JPG
>>106532191
>Wtf are you guys even doing?
kek
>xor eax, eax
is basically reset register, it's a technicality
>>
>>106532230
Yeah, that's what this code is doing.
So what was your point even?
>>
>>106532230
it's sad actually
>>
>>106532246
It means there is no actual ouput in those crustaceans' posts, I'm laughing about them believing to have proved anything, not the 'Cniles.'
I just solidified the Cniles' argument on the matter by highlighting why they [the crustaceans] are wrong.
>>
File: 1669512859224226.jpg (25 KB, 400x400)
25 KB
25 KB JPG
>>106532230
>xor eax, eax
heh
>>
File: 1708011767812109.jpg (44 KB, 459x639)
44 KB
44 KB JPG
>>106532280
I have no idea what are you even trying to say.
OP comparison doesn't make sense. I have shown how to write same thing in both languages.
Take it or pretend you don't see it, I don't care.
>>
>>106531701
Microsoft is migrating parts of the Windows kernel to Rust. Linux added support for kernel modules and device drivers in Rust. Parts of Firefox have been re-written in Rust.
I'd still prefer C++ but C is getting replaced.
>>
>>106532313
>how to write same thing
*the same thing, rajesh
your rust version always returns zero while the c version returns the value stored in data
>>
>>106532331
>your rust version always returns zero while the c version returns the value stored in data
Which always is zero. Wow
>>
>>106532322
>Microsoft is migrating parts of the Windows kernel to Rust
tiniest parts if any
>Linux added support for kernel modules and device drivers in Rust
every driver is still written in c, those that aren't quickly get abandoned
>Firefox
it's not 2015 anymore
firefox has <2% market share
>>
>>106532339
>Which always is zero
in the c version it can be assigned another value
if your rust version doesn't allow that, they aren't doing the same thing
>>
>>106532358
Cope, seethe, and dilate.
>>
>>106532369
>in the c version it can be assigned another value
That would be different code than the one in OP. His code does not modify the static.
>>
>>106532358
>tiniest parts if any
False

>every driver is still written in c
This is also false
>>
>>106532358
>tiniest parts if any
The tiniest parts but the same parts are critical to system integrity and security, parts that, when written in C, lead to (at best) a BSoD and (at worst) to system compromise.
>>
>>106532388
what static? there's no static in there lol
>>
>>106532414
okay I'll bite, what are those parts? where do you get this information?
>>
>>106532388
Rajesh, you're now doing the equivalent of copy+pasting printf("0..100") instead of writing a loop, like was intended, and then defending your work by saying: Yeah, well, the problem only states 100.

This is a real-world problem, it's an excersize about making efficient loops, first and foremost.

The fact that a hundred printf statements are likely molded away by optimization into one fat print string into output, probably escapes your mind.
>>
>>106532434
>what static?
data/DATA
>>
>>106532434
smartest cnile
>>
>>106532451
I have no idea what are you even trying to say.
Have fun living in a world as depicted by the memes.
>>
>>106532487
it's not static in the c code in op
>>
>>106532511
Variables that live outside of object or function scope are commonly called statics.
>>
>>106532451
>This is a real-world problem, it's an excersize
*isn't a real world problem[, obviously]
>>106532508
>I have no idea what are you even trying to say.
You know what, I'm fine by that, thanks.
>>
>>106532517
such variables can be modified and hold values other than what they're initialized to
your rust code simply returns zero, not the value stored in data
>>
>>106532563
the value stored in data is 0. stop coping, cnile.
>>
>>106532563
>your rust code simply returns zero, not the value stored in data
The C code simply returns zero too. Even if it does so via pointless deference that only adds overhead.
>>
>>106532571
>>106532577
not really
it can be modified by other parts of the program
>>
>>106532604
there are no other parts though.
>>
>>106532609
doesn't matter, it's written as if there is
>>
>>106532622
>doesn't matter, it's written as if there is
No, it literally has 7 lines of code total.
>>
>>106532622
doesn't matter, the compiler knows what is there and optimizes accordingly. looks like rustc is better then clang/gcc.
>>
>>106532631
>it literally has 7 lines of code total
and no main function, so it's either a shared library or part of a program
>>
>>106532676
data is not extern though, so it doesn't matter
>>
>>106532686
you don't even know c
>>
>>106532711
non sequitur
>>
>>106532686
You only put extern on files that refer to variable defined somewhere. OP code does not need extern for that variable to be accessible from outside.
>>
>>106527347
>autistically arguing over amount of generated assembly instructions
thank you for reminding me why i should stop visiting this board. if i'd care about that stuff i'd just write stuff in assembly
>>
It's same shit under the hood
>>
I love it when a thread begins looping because nobody reads more than the last 3 posts.
>>
>>106532756
>rust needs glibc to correctly operate
pathetic
>>
>>106527398
what a fucking ugly language
>>
>>106532842
>what is nostd
>>
>>106532928
do that with nostd then
no point in posting the same screenshot
>>
>>106533227
ok?
>>
>>106533341
>__tls_get_addr
it's still linked to glibc lol
>>
>>106533667
are you retarded?
https://github.com/sunfishcode/c-ward/blob/main/c-scape/src/thread/mod.rs#L519-L523
>>
>>106533675
>An implementation of libc written in Rust
lmao
does nostd link against this libc by default?
>>
>>106533711
dumb retard, nothing gets linked. godbolt produces a library.
>>
>>106533722
>nothing gets linked
>@PLT
lmao
>>
>>106533762
yeah, you are a dumb retard. just because it calls a function from the plt doesn't mean it links something.
as usual, cniles have no clue how anything works.
>>
>>106533771
>just because it calls a function from the plt doesn't mean it links something
the absolute state of the rust trannies lmao
show the readelf of a binary you produced this way
>>
>>106533792
what way? this >>106533341 produces a library.
you can use this >>106533675 to compile a binary that doesn't link against glibc for __tls_get_addr.
>>
>>106530427
>You can't write robust non-trivial software with dynamic typing.

99.99999% uptime systems are currently running using dynamic typing. Erlang systems.

Whatsapp is a huge Erlang program.

You can do robust software with dynamic typing if you choose a language that allows for interactive development, like Erlang, Lisp, or Smalltalk variants. Those languages allow you to modify the code while it's running, so you can correct bugs at runtime, without stopping the system, and continually "evolve" the system, while it is running, into a version that is free of bugs.

You're just a junior.
>>
>>106530427
>With every single massive refactoring I do in my code, all I can think is "God, this would be hell without types."

get good
>>
>>106533841
>. Those languages allow you to modify the code while it's running, so you can correct bugs at runtime, without stopping the system, and continually "evolve" the system, while it is running, into a version that is free of bugs.
intellectual masturbation
and a supremely retarded idea
>yeah lets make ALL our programs self modifying, why not?
also i cannot help but notice youre redditspacing...
>>
>>106533800
yeah show us that binary
>>
>>106533906
dumb retard
git clone https://github.com/sunfishcode/eyra
cd eyra
cargo build --example=test-tls
ldd ./target/debug/examples/test-tls

ldd print "statically linked"
>>
>>106533667
__tls_get_addr is not glibc exclusive symbol. It available on many platforms, including proprietary ones.
If you use target like windows or embedded system that use different TLS model you won't get __tls_get_addr. You can also control it using ftls-model/femulated-tls/tls_model
>>
>>106533862
>intellectual masturbation
>and a supremely retarded idea

you learnt to code, now learn to make reliable production complex systems, kid
>>
>cniles can't stop beclowning themselves
>>
>>106527347
I did
there are ZERO jobs with C
>>
>>106527734
>>106527544
I barely understand but i remember watching a vid when he rants about thinking about code as art and being incapable of working on meme crud jobs. Or something like that
>>
>>106533978
it says cargo: command not found
>>
>>106534010
>now learn to make reliable production complex systems
no, quite literally, u

fucking lisptranies i swear...
>>
>>106534269
>AI slop screenshot
literally ban this sick cunt.
>>
>>106533841
you can, doesn't mean you should though.
>>
>>106534287
>noooo you cant use chud gpt as a search engine and aggregator... bc you cant, ok?
cry more no-argument faggot
>>
>>106534076
Cybersecurity jobs? Aren't exploits usually written in C?
>>
File: jobs-rust.png (73 KB, 463x968)
73 KB
73 KB PNG
>>106534076
>the zero jobs
whats youre favorite language, just out of curiosity
>>
>>106534346
>Rust twice
>>
>>106534324
>no-argument faggot
posting flagrantly made up garbage (gAI) is worse than no argument, imo.
>>
>>106534366
>catastrophic reading comprehension failure
>meltdown imminent, all personnel is required to leave the premices
>>
>>106534386
>ok; im a faggot nigger but youre actually worse
keklmao
also: no.



[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.