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


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


Let's have a C thread. Post what you're working on! Show what you're interested in!

WIKI: https://wiki.installgentoo.com/wiki//chad/

IRC: #/g/chad at irc.rizon.net
TG: https://t.me/+itOpQDA2Nbk3ZDZh

Don't know how to write C? Start here:
K&R: https://files.catbox.moe/rfhegv.pdf
KING: https://files.catbox.moe/a875c2.pdf
Modern C: https://files.catbox.moe/xeb93p.pdf
>>
>>102066864
Zig:
> Ugly syntax, has weird @thisToThat "casting".
> Language is in development, shit breaks all the time.
> Retarded keywords and operators overall, tries to be smart.
> Looks like someone tried to merge Pust and TypeScript.
C is simply superior programming language than Zig.
> Captcha: TRUTH
>>
>>102066937
based and captchapilled
>>
>>102066864
Pust:
> Very very ugly syntax, basically unreadable clusterfuck.
> Tpaнниec shill it, but no one considers it seriously.
> Torvalds was cucked into it, so you know it's bad.
> It's not even safe, Ada is truly safe language.
C is simply way better than Pust abomination.
> You will never be anything.
>>
>>102066864
Odin:
> Shilled by 3 people in total, but totally irrelevant.
> It's even hard to shittalk it because of how irrelevant it is.
C will always outperform it's memelang replacements.
> You can't win.
>>
>>102066864
C3:
> A what...? Another C wanna-be replacement? Again?
> Bloated compiler, messy Git repository, mixes Debian with Linux.
> Has a lot of "features" nobody wants like namespaces.
> Raysan was right about namespaces and prefixes.
C3 is a meme, but at least some guy is working on it.
> All your bases are belong to us.
>>
>>102067009
>>102066967
>>102066937
Cool, do you actually code anything in C?
>>
>>102067050
I like namespaces
>>
>>102067050
> nobody wants namespaces
Retard, those are strictly useful and C historical is known for having shitty collisions everywhere
>>
>>102066864
These next memelangs are irrelevant, so we'll keep the jokes short:
--
Nim:
> What happened to semicolons? Is this thing made by Python dev?
Go:
> Stop. Before you say anything good, think: Google. Both suck.
Kotlin:
> HA. Ha. ha... Death.
>>
>>102067060
I use C for 8 or 9 years for now, so naturally, I do have a lot of projects in C.
I use Ada for longer, used Python for few years, dropped it when I learned C.
After C, learned Fortran and assembly, stayed on it, because memelangs are bad.
>>
>>102066864
Any good beginner projects? And I mean ULTRA BEGINNER friendly?
I'm only at the level where I can make something basic like this (on my own, without looking stuff up).
>>
>>102067177
You make that gay city online game where some tranny tried to purge any record of you right
>>
>>102067198
Please ignore my ragespam above about memelangs, I'm writing OpenGL project without extension loader... It's evil.
0) Read about code indentation and alignment.
1) Only Fortran programmers don't indent their code.
2) Try doing some linear algebra in C, vectors and matrices.
3) Then, try generating some PPM images.
Those are a good starting point.
>>
>>102067198
Enable all warning flags, read up on posix libs and learn how 2 makefile
>>
>>102067213
Definitely not me, I'm anti-homo, hence I hate Pust programming language.
>>
>>102067250
Maybe.. im thinking of the guy who tries to justify wanting to marry young girls
>>
>>102067269
Those kind of things are for degererates, I'm against that too, keep in mind that 4 is under r**d right now. Details are on channel.
>>
File: 172451728968442.jpg (20 KB, 450x548)
20 KB
20 KB JPG
>>102067198
Try to make something you'd think you'd use. Even failing to do that will yield lots.
Maybe a local webserver if your interested in the internals of application level networking. Or a text editor, Or a irc client, an image manipulation program, a music player, a rougelike, rpg, a synthesizer, etc. If you want to be a programmer, then you must invest lots of your time into it; improving as much as you can. You don't have to do it in just C.

Also, you can use math.h, exp(1) (this means manpage, `man exp 1') remember to link with -lm, read up on GNU make/meson.
>>
anyone here familiar with openssl library for C?
im doing sockets programming and implemented websocket handshakes, for which im using openssl/sha.h and openssl/evp.h
can anyone recommend a guide for how to use openssl properly?
i want to know what else can be done with it, but it seems fairly unorganized
>>
File: eaxopocalypse.png (746 KB, 640x641)
746 KB
746 KB PNG
The time is near... Maid and GUI Anons blessed us.
>>
>>102066937
Yes, Zig is bad as a language, but the cross-compile toolchain is honestly really good, and can be very useful for C projects.
>>
Will learning C help me get an entry level job in IT if I don't have an undergrad in CompSci?
>>
>>102067406
idk what the situation is in other countries but a bachelors in compsci is a requirement for software engineering
for just "IT" you could look at certs - not sure if theyre a meme
definitely something to put on your cv, but just look at current job listings
>>
>>102067213
>>102067269
That can only be Michael E. USA, more widely known by his nickname with a double E
I am obfuscating it here instead of typing it verbatim because I don't want to summon him
>>
>>102067406
Having projects will. I started with C and I used a project in Python to get a job. You need to realize the programming language doesn't matter too much, it depends on what you want to achieve.
Knowing C and ASM is very important to shape your perspective, so definitely learn at least the basics.
>>
>>102066937
>ugly syntax
It's not that bad. Takes a bit to get used to but it's worth it.

>Language is in development, shit breaks all the time.
And. . .? You're expecting a program not even in 1.0 to be perfect? Unreal expectation.

>retarded keywords
Like what?
>>
>>102067545
>You need to realize the programming language doesn't matter too much
this - i picked up C# the evening before an exam and finished 15 minutes before the next person
when you know related languages (C and C++ in my anecdote) you can immediately pick up "new" languages
>>
File: clayer.png (1.29 MB, 1280x720)
1.29 MB
1.29 MB PNG
Slayer!
>>
>>102066864
how do we fix the retarded parts?
is the stream the first or last parameter in the f*() calls?
why is there memmove, memcpy, and strcpy?
why is the return behavior different for every fucking thing?
>>
>>102066937
genuine question
any reason to use a C compiler over a C++? I can still write C code but with the QoL features that C++ provides
Also where can I learn C17 as a C++ developer?
>>
>>102068551
genuine question
are you fucking retarded, sir?
>>
File: 1723248889224826.webm (449 KB, 1280x692)
449 KB
449 KB WEBM
>>102068551
C17~==C11
>>
>>102068577
AFAIK c17 is c11 but with bug fixes, well now I realize you're right. Still I can't find any "modern" guideline one writing C11 code such as the CppCoreGuideline for C++
>>
>>102068564
It is perfectly logical to prefer C++ over C if you can get a C++ compiler. C++ is C without handicaps. If anything, you're the retarded one for not being able to learn it.
>>
I am ready for your slings and your arrows /g/.
>>
File: 1724338119316100.jpg (57 KB, 590x445)
57 KB
57 KB JPG
>>102068984
>>
>>102068600
>CppCoreGuideline for C++
Independent original thinking is impossible for you anon?
>>
>>102069491
of course not. every c++tard preaches the gospel of design patterns.
>>
>>102069037
>VLA
Get out
>>
>>102069902
> no vla
Get out
> Fixed sizes, stack, heap, or db
The only choices - know your circumstances
>>
>>102067364
>she doesn't know
>>
>>102067077
why would you acknowledge this in public? there may be children around here.
>>
>>102067094
>>102067077
C has namespaces already it's called internal and external linkage
when you put functions in different translation units, that is a namespace.
>>
>>102069829
>>102069491
or perhaps I like to analyze what (((experts))) and experienced devs suggest, and formulate my own opinion? I mentioned the CppCoreGuideline because it's a decent resource to get a pulse on best practices
>>
>>102070294
best practice is to not use c++
>>
File: 1722964196990372.jpg (90 KB, 461x465)
90 KB
90 KB JPG
>>102066864
What is the best programming LLM that can be ran locally that is good at C and C related libraries? C++? I want to finish what a holy OS should have always been w/ some powerful AI features.
>>
Is it retarded to create a enum inside a function to index an argv by name that's passed into it like?

int function(char ** argv)
{
typedef enum
{
NAME,
PHONE,
ADDRESS
} arg_index;

puts(argv[NAME]);
return 0;

}


if so what's a better alternative?
>>
>>102070399
No, best practice is to use what you can.
If you can use a C++ compiler, then you should use it.
Nothing against C programmers, but C++'s features like generics give it an evolutionary advantage over C.

>but anon all you need is void*

No, you *need* more.
Say you have the following C code:
typedef union Token_Value {
int i;
float f;
char* str;
} Token_Value;

typedef enum Token_Type {
IDENT,
LIT
} Token_Type;

typedef struct Token {
char* src;
Token_Value value;
Token_Type type;
} Token;


In order to create a vector of non-primitive types, you need to recursively free the pointers, which fucking sucks.

Along with an incredibly useful STL you can use things like std::optional and std::variant in this example.
>>
>>102070508
it's good
>>
File: 1722936324967851.jpg (52 KB, 750x675)
52 KB
52 KB JPG
>>102070510
>::
>>
>>102066864
Is C a hobby language?
There's no way that's a substantial job demand for C programmers in 2024, right?
>>
>>102070895
LMAO
>>
I've been scratching my head trying to implement daemon-client IPC using UNIX domain sockets:
>Split daemon into two threads
>One enqueues requests and one services them
>This means I cannot use the same socket for Rx and Tx though
So, either I don't go with a listener/enqueuing thread and just make it all be done at once (and relying on inherent socket queuing) or I open another socket to do Tx back to the client - but that adds quite a lot more complexity.
>>
>>102067050
>> Has a lot of "features" nobody wants like namespaces.
says the man who will smoke a whole pack if a C library prefixes its functions with the "wrong" casing
>>
File: gnu_stdio.png (315 KB, 5698x731)
315 KB
315 KB PNG
picrel is the header hierarchy of GNU glibc's stdio
>>
File: musl_stdio.png (33 KB, 653x269)
33 KB
33 KB PNG
same, but under MUSL
>>
>>102068509
>how do we fix the retarded parts?
seems we agree, but i will exclaim it explicitly: the standard library is the most retarded thing about C
>>102068509
>is the stream the first or last parameter in the f*() calls?
has to be the first, otherwise vararg functions would get real awkward
>why is there memmove, memcpy, and strcpy?
yes...
>>102068509
>why is the return behavior different for every fucking thing?
fucking exactly. `void thing(char**); // stores result in i` sure whatever, BUT RETURN i TOO FFS

im also very annoyed how there are no function variants that auto invoke perrno
>>
>>102067198
I made a calorie calculator and I use it sometimes.
Inputs mass, the calories you want for the meal, the calories and protein for 100g of meat, veggies and carbs.
Outputs the right mass (grams) of meat, veggies and carbs for your meal, as well as the proteins you'll get out of it.
I used only printf and scanf.
>>
I thought I'd report here as well >>102071978
hi anons, I'm learning C++ and I wrote a terminal clone of htop, right now it's simple and prints total and core usage in terminal. It only compiles on Linux right now.

Could anyone take a look and verify it is correct? I checked it against htop and the values I read are within margin of error but not exact. I attached code in rentry paste rentry dot co/7w3vywf9

thank you!
>>
>>102068509
>why is there memmove, memcpy, and strcpy?
why is memcpy and strcpy bad?
>>
>>102072054
nta, but i think the problem is that copy is abbreviated, but move isnt
>>
>>102072146
that is a minor problem, and anon made it sound more serios. From docs it seems the only difference
>memcpy src and dst should not overlap or this is undefined behavior
>memmove should allow src and dst overlap
>>
>>102066864
Where can I buy the book for cheap since most physical copies cost a shit ton
>>
>>102072054
Not bad per se, just different functionality.
(Overlapping/not overlapping).
The real issue in practice with strcpy is the possibility for buffer overflows (hence strncpy) and worse is also the possibility for lack of NUL byte termination.
The latter can be an annoying footgun because C-strings don't carry any metadat about their length and so a string lacking the terminating NUL byte is just UB waiting to happen sometime down the road (generally in the form of buffer overflow/failed bounds check).
>>
>>102067050
any good c3 tutorials?
>>
>>102072256
You'd think that's what strncpy is for but it isn't and you shouldn't use it for that
>>
File: 1724527485182120.jpg (46 KB, 535x372)
46 KB
46 KB JPG
>>102066864
>>
Still in dev hell of my GUI library. While I have a working prototype. I'm currently rewriting it from scratch (and adding new features as I go on) in a slightly different and improved (imo) API style. And the functions that were handling the config have been exported into their own library that now defines a whole configuration language (CCFG), parser implementation in C and thick Ada bindings.
Also, pic related, currently I'm experimenting with "smart corners" (for a lack of a better term). Aka, if configure the window to have radii (rounded) or chamfer (cut) corners, then widgets in said corners will adopt their shape with appropriate padding applied.

>>102066864
Also, check out this book, its interesting especially from an historical PoV.
https://progforperf.github.io/Expert_C_Programming.pdf
>>
>>102072823
>While I have a working prototype.
*But I do have a working and usable (for simple things) release.
>>
>>102072594
I'm well aware that strncpy has its own set of problems.
In realite, if I'm not certain of the bounds I just use strscpy, too bad it isn't in the standard library and I have to grab my own implementation each time.
>>
>>102072388
Watch Tsoding's review of C3 programming language, from start to finish, it's around 2 hours, and you'll know why it's bad...
>>
xolatile the russian autistic incel in his 30s that spent 10 years "programming" in c making toy projects
he gets all his opinion from 4chan and internet celebrities
he has negative experience doing anything worthwhile
noone in his gay irc has a job
they all masturbate and larp like it's 1999
c++ and rust are misteries to them
their brains stopped developing when they hit their early 20s and they have been repeating the same things over and over
there's no hope for any of you worms
>>
>>102067437
Why would it be a requirement? I swear I heard people get jobs as software engineers without college degrees.
>>
>>102073281
And it's bothering you because?
>>
>>102073384
>there's no hope for any of you worms
>plural
bc were not using rust
>>
>>102073523
I am learning C and it's fun, especially memory management, having complete control of when I allocate values and release them is like some power fantasy, makes you feel like a wizard or something
>>
>>102073612
power fantasies are the best reason to use c and the best part is you can do them at work, its like being a police
>>
>>102073612
based.
i learned C after having used python for years, for school purposes
the learning curve was real
but now i master the language i love the fuck out of it
in the immediate present i write a computer vision tool in it
>>
>>102073674
i also learned C coming from python
only concepts it was hard to into were passing arrays to functions and pointers
i think this is because python hides this from new programmers
it just "werks" but you make mistakes like below and it blows up:
mat = [[0] * 5] * 5    # what the fuck is a reference?
>>
WHY IS IT SO FUCKING IMPOSSIBLE TO MAKE A MODERN C??,
>>
>>102073281
its quite funny to me that you managed to get all of those statements wrong
>>
>>102073743
You can't beat perfection.
>>
>>102073612
IMO it gives a real deep understanding of sys internals, in other words you understand why programs behave how they beahve by their behaviour
>>102073739
cpps vector and so on are pretty convenient...
>>
>>102073743
doing that would ruin the power fantasy, better if it gatekeeps itself
>>
>>102073763
i use C++ for competitive programming
i use C for my based projects
>may i see one?
no
>>
>>102073743
Because C is already good and everything you would want out of modern language was masę in it, the problem is gathering that useful knowledge in 1 place, to sum it up, I think they should focus on improving the existing wheel rather than keep reinventing one, for example by making better debuggers and intellisense to make writing code faster and more efficient
>>
>>102073739
>only concepts it was hard to into were passing arrays to functions and pointers
>i think this is because python hides this from new programmers
that was also my exact case
"nuh start with paithon" meme is actively detrimental to learning programming
it teaches you wrong, and you have to unlearn that shit when you use pretty much anything else

i wont harp on python too much, it can have its uses
but it being a beginner friendly language is a fucking meme that needs to die a horrible death
>>
>>102066864
I've been using cpp but I feel like OOP is forcing me to jump in too many hoops. How do I pivot to pure C ? is there a book or something on the subject ?
>>
>>102073762
>>102073762
>>102073764
Bro modern C is hacking together macros and keywords not in the standard and passing a hundred flags to the gnu coompiler
Its a fucking mess
>>
>>102073743
you have compound literals, macros, and various useful compiler directives like always_inline or constructor
nobody bothers modernising C bc its users do that themselves
>>
>>102073813
>Its a fucking mess
youre being dramatical
but yeah, better training would be welcome.
idiomatical C is only useful if you write opensores libs
>>
>>102073778
I really like that one can optimize the shit out of C code, not so much with C++. Just yeet all the useless functions, variables and stuff you don't need.
>>102073794
>beginner friendly language
Just no, coming from BASIC then C# and later C, though it can be quite nice (due to it's large packet base) for prototyping certain things like machine learning
>>
>>102073794
i always tell people it is deceptively simple
my friend is learning python on his maths course, so i will make an effort to teach him about references
remember that most python fans dont even know about type hinting or that:
a ,= [123]
print(a) # 123

they have such a shallow understanding you might as well hire a senile C programmer to do their job
>>
>>102066864
https://www.cc4e.com/lessons
Maybe add this to the links. Free course follows K&R. Site also has archives for his C++ and Fortran courses.
>>
>>102073856
>deceptively simple
>people usually have a shallow understanding
whoever worked with python with any amount of seriousness will say the same about it
>>
only c programmers get stuck in language wars because they have nothing else to do and no experience in anything else
>>
>>102073900
>notice me senpai
i did. that was disappointingly retarded.
>>
>>102073911
meds
>>
>>102073932
this is a wendy's sir
the hospital is down the alley to the left
>>
>>102073947
for you
>>
>>102073960
nu uh
stay in btfo
>>
>>102067358
openssl/ssl.h
theres not many guides for the openssl C library sadly. reading the documentation will help, theres some questions on stackoverflow and you can always ask new ones. be wary of old code examples
>>
>>102068551
>any reason
none
>>
>>102074129
>t.nocoder
vlas
>>
>>102074204
name 1
>>
>>102074263
>t. doesnt know what a vla is
fukken lmao
>>
>>102074263
bob
>>
>>102073960
>>
>>102074324
>he doesn't know about useless thing exclusive to useless languages like c, fortran and ada
>>
File: funny-animals-seal.gif (3.61 MB, 434x250)
3.61 MB
3.61 MB GIF
>>102074520
>yeah bro, just block your cache with a fuckass array
>or even better, make it exist intermittently so that each time you enter the scope you load, then dump pages
>>
File: seal-clapping.gif (1.44 MB, 360x270)
1.44 MB
1.44 MB GIF
>>102074520
this picrel conveys the idea much better
>>
>>102074571
>>102074584
get a job
>>
File: 1724571213466688.jpg (28 KB, 499x481)
28 KB
28 KB JPG
C seniles can't even implement a good multiple source BFS
>>
>>102074609
thanks to knowing this kind of shit i dont need one
>>
File: kot-ANSWERS.png (153 KB, 500x392)
153 KB
153 KB PNG
>>102074619
wtfs about bfs thats supposed to be hard?
its literally just a way of traversing a graph
>>
abstractions are great at filtering retards
have fun living like cavemen
>>
>>102074682
imagine caring about yous
also
imagine seething that hard in the first place
i still aint gonna use rust. bc it sucks.
>>
>wrote a fuse filesystem in C, implemented the most necessary features
>fixed all compile and static analysis warnings, wrote asserts where necessary
>running tests from a bash script
>generating code coverage with gcov
this is the first program that i got far enough to write tests for, normally i refactor stuff all the time, so i wasn't even thinking about writing tests before having a stable API.
With a filesystem it's much easier, since the filesystem calls are the API, and testing the whole program from outside seems to make more sense than calling functions in C.
I like it, hope it will help me find regressions when they happen.
>>
>>102074690
you no internal monologue
>>
>>102066864
/Dead language general/
>>
>>102074778
>sad homonem
ugh youre boring.
find new material
>>
>>102074812
>sad homonem
>>
>>102074782
>no rust discussion thread on the log
>121 posts in this one
geg.
ur seething very very hard
youre boiling with rage
barely containing it
raw, unadulterated, but absolutely impotent hate

i wish i could see your face
>>
>>102071857
fputs and fputc have it swapped
>>
>>102074782
maybe make a helpful rust thread /hrt/ while we /chad/s offer help and discussion
>>
>>102074040
found this:
https://docs.openssl.org/3.3/man1/openssl/#command-summary
cheers
>>
so, im making this thing: a graph extraction tool based on CV ideas i had a while ago. entirely written in C of course.

and i will want to benchmark it (i have something like 5 hrs coding left to do and obv. according to the 90/10 rule its gonna be two days im procrastinating on that)
i checked around and it seems the industry standard is to start with sobel and then extract your data from there
but the initial gauss filter alone may be slower than the whole process if the whole image fits on cache (i access my data in an unordered manner.)

so now the question:
does any of you /chad/s know of something faster than gauss + sobel, that does graph extraction?
>>
>>102066864
Brehs... why isn't this working? It's mocking me
>>
>>102075076
nono
its working ackzactly as intended
when you do
if (gender == "male")


youre not checking the letters one by one
youre checking if the addresses are the sameyou should use strcmp() instead, or even better
implement it yourself
>>
>>102074865
i am aware. thats the problem
>>102075076
because == compares the pointers and not the string values. use strcmp and dont forget to negate the return value
>>
I noticed the pdfs in the op are trash, anyone have alternatives?
>>
>>102075139
k&r is easy to find
https://colorcomputerarchive.com/repo/Documents/Books/The%20C%20Programming%20Language%20%28Kernighan%20Ritchie%29.pdf
>>
>>102075076
Because C is a tranny language. Strings don't work like they do in a normal language. In any other language like Lisp, Python, JavaScript, BASIC, Pascal, PL/I, COBOL, Fortran, Ada, Algol, OCaml, Standard ML, Haskell, machine code on some CPUs, etc. this makes perfect sense and does what you want. C is trans-PDP-11 assembly so it works like a PDP-11. Those "strings" are actually pointers (but not 2-byte pointers because it's not really a PDP-11) to characters followed by a null character (0 byte).
>>
>>102075158
I am trying to find the k&r one but with pdf chapters and preferably a better cover resolution
>>
>>102075181
fair.
i wouldnt bother tho
you wont be coing back to k&r very often, its merely a manual for syntax. its not even exaustive.
no word about compound literals for instance
but thats advanced shit
and k&r is the functional basics. its a good idea to start with that even if that book doesnt cover everything
>>
>>102075263
I already know C++ and some C, what book should I read that covers everything from basic to advanced topics?
>>
>>102075393
right thread, wrong person
the only texts i used were the manual and other people' or gpt's code
otherwise i learned from discussions

this guy is on my radar, maybe his works will suit you:
https://agner.org/optimize/
>>
>>102075473
>manual
i mean the standard
>>
>>102067406
Yes if you want to work with microcontrollers.
>>
>>102075393
ackshually
>https://www.agner.org/optimize/optimizing_cpp.pdf
this should fit the bill pretty well
im having a read (finally, after years of doing anything else) and the guy covers everything starting with basics
>5 Choosing the optimal algorithm
>>
>>102070508
No are you stupid a function is just a fancy routine aka it's just a program

If you're talking about just an enum then yes, cause this doesn't' need to be in a function, what you want is a variable
>>
>>102073799
What a convoluted question. Just don't use Cpp features. For example, many things that can be expressed in C++ can be expressed in C using algorithms and data structures as opposed to language provided features.
>>
>>102075614
I am looking for a C book, not a C++ one
>>
>>102075773
get a job
>>
>>102075076
general tip for c is not to use any function (anything that looks like foo() ) without knowing what it does.
>>
>>102075794
>7.12 Branches and switch statements
i know
but its a book that's about the mechanics of c and c++
theres only certain passages that are c++ specific

its not his only book either but honestly i wish i had read this book sooner
i know the vast majority of this stuff by now, but it took years of very inefficient, sometimes accidental learning
this book is literally what you need to know to be confident when you optimize your code
whether in C or C++ youre just expressing the ideas and youre playing on mechanisms that are exposed in this book
>>
>>102075794
for instance:
>Register variables
>The most commonly used variables are stored in registers (see page 27).
>The maximum number of integer register variables is approximately six in 32-bit systems
and fourteen in 64-bit systems.
this i didnt know.
i mean i knew that was a thing but i didnt know the exact number, and i thought it was higher.
just as useful to know that in C as in c++
>>
>>102075996
>>102075885
Thanks! I will keep it so I can read it after I finish the K&R book.
>>
>>102076049
my exact thoughts about when to read this book
maybe allow yourself some time to get confident with C first tho
write a server, or a wolf3d clone (moderately complex projects where you have justification to use a variety of C's features)
i think its important that you truly absorb what you will have learned in k&r.
because this book is about inner workings of the cpu and the compiler, you cant be unsure about what a pointer is or you will be very inefficient with needing to look up shit while youre learning pretty complex stuff already
divide to conquer kind of deal
>>
>>102076049
Don't read K&R it's an outdated and poorly written book, sir. You can't even compile the first example in the book using a modern compiler, sarr. C Programming: A Modern Approach is a better book, sir. Plesse sir.
#include <stdio.sirrr>

main()
{
printf("Hello sirr\n");
}
>>
>>102076146
>i think its important that you truly absorb what you will have learned in k&r.
Kys retard, K&R is plagued with bad examples and outdated code conventions. Stop recommending it.
>>
>>102076192
ok
i have no real feelings toward k&r in one way or another
>once youre done with the basics of c, do some practice, and after that, do agner fog
here
fixed it
>>
>>102067437
if i were to prove myself with a huge project with good code would i get a job nonetheless?
>>
>>102076146
>because this book is about inner workings of the cpu and the compiler, you cant be unsure about what a pointer is or you will be very inefficient with needing to look up shit while youre learning pretty complex stuff already
K&R has nothing to do with the inner workings of any CPU.
>>
>>102076337
im not talking about k&r you dweeb
im talkin g about this:
https://www.agner.org/optimize/optimizing_cpp.pdf
>>
File: image-1.png (412 KB, 742x776)
412 KB
412 KB PNG
>>102075076
Cute little misunderstandings
>>
>>102076181
>>102076192
I heard the exercises are great. Is it still worth to read the book just for the exercises?
>>
File: 1589800920164.jpg (291 KB, 2560x1439)
291 KB
291 KB JPG
>>102074841
>>102074884
Learn a modern language.
>>
File: macron-and-boris.jpg (99 KB, 876x1178)
99 KB
99 KB JPG
>>102076499
im not a "modern audience" tho
>>
>>102076499
ack-shually
i know opencl, and can understand glsl, and cuda its just that i dont speak these languages fluently

go neck yourself
>>
>>102076580
you have no useful skills
if you did you would have a better job
>>
>>102076593
*looks at big corpo*
if you desperately want to get into a sinking ship, who am i to disagree?
on the other hand not everyone can do marketing, lead and codemonkey at the same time
so its only natural that some of you lemmings will perish
>>
>>102076621
you're so retarded anyone else would have to be baiting to come up with this
>>
>>102077001
well, since you lack imagination, have this:
i feel pretty vindicated knowing compute and conuming my own products
ill be branching out soo, too
and afaik javascript isnt really useful in robotics...
>>
>>102077068
get a job
>>
>>102077145
i had a company. i didnt need to work in 5 years, and have enough money in the bank to live another one and a half
think about it when you commute to your work, tomorrow
>>
>>102077157
>i had a company
I am sorry for your loss
>>
>>102075076
gender == "male" // incorrect
strcmp(gender, "male") == 0 // correct
!strcmp(gender, "male") // correct & preferred
>>
>>102077157
ok neet
have fun masturbating
>>
>>102077178
i left it to my associate once i ate well enough
i went on to study programming.
sadly for him, luckily for me, that was in mid 2019 just before the coof lockdowns
the company is no more, not in any official capacity at least.
he wageslaves and takes jobs from our list of clients off the books, so that mfer be eating good
>>
>>102077253
>mfer be eating good
ebonics is not tolerated on this board
>>
>>102077253
its been 5 years and you're at permabeg level, sad!
>>
>>102077267
you have no say abt that, doe
youre an /lgbt/ourist
>>
>>102077298
whatever lets you sleep at night, wagie
you seething enhances my feeling of happiness and makes me appreciate my position even more
>>
>>102077319
ok neet
>>
>>102077302
>i be yo teacha fo dis year
youre either a nigger or a faggot raised on nigger content
>>
>>102073281
Yes (not really). Also, I had a job, worked as a guard for 3+ years, until 2 months ago, didn't extend my contract so I can have some free time to chill.
>>102073900
Yeah, only C people get into language wars, and there's a flood of Pust, Zig, Nim, Hare posters, and some C# and Odin hard shillers.
>>102075076
That's sad, and it seems like you never heard of cmp, cmps or repne CPU instructions, or know why they're used if string literal is embedded.
> Captcha: PWNED
>>
>>102077777
ok neet
>>
>>102077777
checked
>>
>>102078068
>>102078168
Oh fucking hell, I just noticed >77777<, I wonder what would [s4s] say about that...
>>
>>102078197
Shut the fuck up namefaggot.
>>
>>102078207
no :)
>>
>>102078243
Based.
Thanks.
--
>>
incel low iq freak
>>
>>102077593
neither
its actually a french idiom
>il mange bien, clui la
another french-originated idiom, also use by niggers: "senpai"
hilariously enough, it appears im the one who introduced that idiom.
its supposed to be "famiglia", and i used it to refer to the urban gang i was in at the time
turned "family", then it spread out in my city
then it was passed through to weimerica, and they put in their twist to it- turning it to "famalam"

>>102077777
checked.
based xolatile-take
>ah, only C people get into language wars, and there's a flood of Pust, Zig, Nim, Hare posters, and some C# and Odin hard shillers.
were creating interfaces for whatever we do
so, we have strong opinions about em. who would have thought...
>>
>>102078295
>senpai instead of "f/am"
thats being extremely out of touch

thats not what f/am' means
it denotes a degree of famliliarity, not a gradient of hierarchy
>>
btw
when i disclose illegal stuff i did, its way past prescription delay
>>
>>102078367
meds
>>
which is 10 years for conspiracy to commit crime in my country.
its things that happened 12 years ago
>>
>>102078381
yeah if you want to become a submissive normgroid with hormonal issues
otherwise you take things as they come and do the best you can out of that
>>
>>102078398
if this is your best I feel bad for you
>>
>>102078430
what the fuck is that even supposed to mean?
what are you implying here?
>>
>50ylence for the next 15 minutes til soemo other lgbtourists picks up the train of thought
im not 100% on this one, but if thats what heppens, i called it
>>
>>102075875
General tip that filters 99% of hn and reddit
>>
>>102078367 >>102078381 >>102078383 >>102078398 >>102078430 >>102078437 >>102078455
fucking rust trannies leaving botted comments unrelated to anything in this thread
MOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOODS
>>
>>102078437
english nigger, do you speak it?
>>
>>102078483
>loser argument
>waaah jannies!
good luck with that
this aint /lgbt/, faggot
>>
File: spacewar-2.webm (2.5 MB, 800x600)
2.5 MB
2.5 MB WEBM
>>102066864
I've been working on a board game-like, but the design is fundamentally flawed. You can't attack through jump lanes, so the AI reaches a degenerate state when systems start filling up.
>>
>>102078527
well enough so that you do the effort to carry the message the remainder of the way

just fill in the blanks, itll be fine
if the message was worth being anal about, i would have paid more attention to details
>>
>>102078563
if you had any skills you would get a job
>>
>>102078527 >>102078534 >>102078563 >>102078632
shut up you fucking transvestites
>>
>>102078632
since i have skills i create industry
if you had any you would have done the same
what i did before- construction
what im doing now- ai. symbolic as well as ml

and since your skillset isnt really that good
you need the support of a company to have any worth.
and thats why you get paid a penny on each dollar you generate, when i eat all the revenue, minus taxes ofc.
bc everyone is the taxman's bitch regardless of how successful you are

but being on a higher social rung than you are is comforting enough for me
>>
>>102078699
Shut the fuck up, schizo.
>>
>>102078825
dont engage me then
whenever you see someone posting in lowercase just close + hide the thread
im not the only one lowercasing everything, but its a good practice for you.
you have fuck all to say.
>>
>>102078855
you're schizophrenic and need to get medicated before you do something to others
>>
dear /g/
i cant be the only one doing the btfoing all the time
you need to keep the fucking degenerates under their fucking rock
or you will get a log thats filled with consumergroid shit like in the past 48 hours

the unwritten rules are:
if op is off topic
then theres no limits. except outrageous shit like gore or nsfw.
and ywnbaw depends on whether which mod is on the board currently

if op is on topic
you gotta stay on topic too
you can still be brutal all you want
but you gotta stay on topic too

simple as fucking ass
janny cant report to mods situations that prove he is bad at his job

another thing you can do is:
mass report
then the mod gets a notification that a janny is slacking
and janny gets kicked in the arse
and if janny is rotten
then you get a situation where pedoes are in pedothreads with deleted picrels
but at least they aint shitting up the whole fucking board into unusability
>>
>>102079070
get a job
>>
>>102079112
in a way
i already do
its just that i am the one deciding when i work and when i dont
>>
Some C code for a bump...
>>
And something for function pointer management...
>>
>>102079526
try __attribute__((always_inline)) if youre on gcc
its a real gamechanger

if you want to force inline throughout compilation units use -pipe and -fgnu89-inline flags

you just have to prefix your declarations with the keyword "inline"
and instead of the compiler directive you put "extern" in the header
>>
>>102079526
>>102079602
(clarif:)
force inlines give you the power of a macro with the flexibility of a function, and the added bonus that debug valgrind also treats it as much
i am of the opinion this feature should be standardized
>>
>>102079602
>i am of the opinion this feature should be standardized
it is in fucking rust
you put "inline" between brackets and thats it
we need this shit
its a powerful tool
>>
>>102079602
>its a real gamechanger
it has zero effect most of the time and looks ugly
so no
>>
>>102079754
>t. rustrannör
opinion discarded

because if you were a c programmers that would be insulting

the difference is that its the only true zero cost abstraction even if you have to control that manually and keep track of how big your functions are

the other day we had a code duel with one of your fellow crabs and he saw a 10% improvement in performance from merely inlining his shit

but i digress
which i wouldnt mind if i werent unsure if youre worthy of a mere digression to begin with
youre an extremely disagreeable person
why would i help you in any way?
>>
> inb4 now plays nice
yeah yeah yeah
we all saw that before

we let you in
then you shit up the place
and were at the exact same point we were at one year ago
>>
File: 1722380161825273.webm (412 KB, 1024x1024)
412 KB
412 KB WEBM
>>102077777 (checked)
>>102079820
Inlining is strictly a good idea. If you don't worry about code size, the speed benefit from removing the function call overhead is a huge gain.
>>
>>102066864
any recommended minimalist compilers for learning C on windows 11? just as a hobby really

i remember trying MinGW a while back and windows was flagging it as potentially a virus
>>
>>102080668
get a job
>>
>>102080668
>https://nuwen.net/mingw.html
coompiled by one of the people working on Microsoft's sepples implementation
>>
>>102080593
you have to account for the fact that your code is also data, but with different permissions.
your code lives in the same cache as your data, and follows the same rules.
if you need to drop pages because of code, youre still dropping pages.

90% of the times i inline code its two lines and i leverage the fact that a function has its own scope, for avoiding namespace pollution purposes etc
i mean
inlines are in 90% of cases an organizational thing for me

and thats exactly why i thing thats such a big thing bc it drastically changes the way you code
its literally like you play with legos
its a couple more lines than generics
but its so much more powerful because youre not constrained to a certain context
its more granular so obviously it gives more flexibility...
>>
>>102080593
AND
force inline doesnt in line all the way down so to speak
as in
it will just inline into the scope its called in
so you can have inlines but who get called like a normal function to avoid code volume runaway
i absolutely love the fuck out of force inlining
it is my 2 complaint s , the only thing im missing when i operate in c (the other being __attribute__(( constructor)) for everything boilerplate when you include your codebase. its just insanely comfy)
>>
>>102079602
>>102079637
Thanks, but it looks ugly, and I use gcc exclusively now, uninstalled tcc and clang.
>>
>>102080786
it does look ugly im not gonna say otherwise
we need to get it standardized i say
so that we get a clean codeword instead
>>
>>102080786
>>102080812
its literally adding force_inline over inline
and i would hazard that all the major compilers support that already
>>
and also constructor attribute
you shove all the nasty boilerplate in it
its clean

yeah you gotta pay attention that you dont call something that hasnt been initialized yet
but even in an unordered manner
its so fucking powerful
and its clean
cleeeean *ngh self erotic noises*
>>
im kinda d runk rn
but even then
when i witnessed the power of constructor
everything became clear
my understanding expanded
and i shed a tear of joy
for i have undrstood
one of the fundamental pillar of reality
and i rejoiced
and shared
what i still do until this day
to celebrate the wisdom of our predecessors
their love for the art
and the opportunity to subsctibe to to this august lineage
>>
rust cant possibly give you these kinds of feels btw
i pity the fool who does rust
theres a whole plane of reality theyre missing on
>>
Alignment driven development...
>>
I digits then Javascript > C
>>
>>102080998
Rust is fine and way better than shit like Java, C#, Python for almost any use case when starting a new project. Fuck I would rather use it than C++ in most cases. It will never replace C in areas C dominates because no one is going to want to rewrite the last 20-40 years of OS code that works perfectly, in Rust, it's an insane thing to do.
>>
>>102081762
As soon as the US g**ernment shills something, you know it's unsafe or retarded, and that you should stay away from it.
>>
If you can't code and run a fizz buzz in PDP11 assembly, you are not even close to be a true C programmer
>>
>>102082022
Yes, every C programmer should know about basic assembly, either AT&T (bad) or Intel (good) syntax, and system calls.
>>
>>102069929
Use alloca at least.
>>
>>102081945
Why are you on the internet using a website made, in part, with http?
>>
File: Si guasta qua.png (10 KB, 1043x154)
10 KB
10 KB PNG
Guys, a little help with troubleshooting the reason why my programs in C crashes at "free(attuale)->nome" (don't mind the language, I'm italian).
This dynamic string gets initialised correctly and as you can see, right before freeing at "attuale->nome", I can even read it.

For context: this is snippet is part of my university project where I need to handmake all the data structures so, to be clear, the dynamic string is itself part of a dynamically allocated struct.
I've been stuck on this line, because there's no human reason it shouldn't be free but only read, and it has halted all my work for a copule of hours.
>>
>>102083393
Because HTML is more readable and overall safer systems programming language than Pust.
>>
>>102083602
can you share the struct?
>>
>>102083602
i may be retarded, but is the same element (attuale->nome) being dereferenced as both %d and %s?
>>
>>102066864
#include <iostream>
using namespace std;

int main() {
int week = 7, heart = 3, phone = 4, laptop = 2020;
double android = 10.0;

cout << "Hello, new guy to C++. Been learning for about " << week << " days or so on a free app." << "\n"';
cout << "I have a calypso " << phone << " that runs off of android " << android << " I believe, and a lenovo " << laptop << " laptop." << "\n";
cout << "so far I've just passed the %=, *=, += parts." << "\n";
cout << "I'm doing this purely off memory right now, and any replies I make here in the future will be in the same format so I can practice. Also anyone know what rc4 encryption blob works for /g/?" << "\n"
cout << "any and all advice would be apricated. <" << heart;
return 0;
}
>>
>>102085046
#include <iostream>
using namespace std;

int main() {
cout << "Oh wait I didn't see the part in OP telling me to start there if I'm new." ;
return 0;
}
>>
> what did I just read
>>
This is a 60 iq question but why C over C++? Isn't C++ just C with objects? Is the point of using pure C to be anti object?
>>
>>102088670
C++ has shitton of non obvious hidden behaviours, like calling destructors when moving objects (e.g. appending to vector).
That and absolutely monstrous inconsistent stdlib in newer standards.
If you're starting with C it's difficult because you need to write lot of basic stuff yourself, but at least if your code fuck up you know it's your fault. If you're starting with C++, you're gonna wrestle with the language itself, not sure if it's doing something under the hood.
>>
>>102088728
I'd be interested in C then because I actually default to just writing my own implementations of things rather than calling some .function()

My only question though, are these self written implementations going to be a lot slower than C++ library implementations if I'm not a complete genius?
>>
>>102088780
they will be faster in most cases
>>
>>102088836
XDDDD
>>
>>102088780
C++ algorithms are state of the art and cutting edge... AND insensibly robust and generic, so it all balances out to "no one fucking knows how it will perform"
>>
>>102088780
In most cases probably, however C++ stdlib containers and functions are generic, it's not uncommon for people writing their own special case versions that are faster.
>>
File: 1724662660376465.jpg (173 KB, 1024x1024)
173 KB
173 KB JPG
C programmer casually choking Pust programmer...
>>
>>102092222
get a job you fucking low iq loser
>>
>>102093157
https://www.youtube.com/watch?v=a8MZBUoQt68
>>
>>102093157
Oh no, I hurt someones feelings... D:
Anyway, Pust sucks, no one should use it.
>>
>>102088946
wtf are you smoking
>>
Is learning the basics in C# enough to get an entry level job as a net dev or software engineer if you don't have an undergrad in CompSci?
>>
>>102095159
i have encountered this at least
terminate called after throwing an instance of 'std::invalid_argument'
what(): stoi
Aborted
>>
lol



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