[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


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: huh.jpg (33 KB, 833x359)
33 KB
33 KB JPG
Been reading the bible (K&R).

This almost filtered me...
>>
lmao yeah, you know that book's for unix?
you should try a cygwin console homie, and emacs.exe.
>>
>filtered by a fucking temperature converter
>worships C
Clockwork.
>>
>>106811417
GPT-5 is your friend
>>
that is outdated. you should be wrting in visual basic coode 2025.

>>106811487
AI is very good for making efficient app.


No one uses c because it is very unsafe very slow and not very good.
you should learn full stack development with javascript mysql php.
there is very many good software service to automate the process.
>>
>>106811526
thank you saar, please do the needful
>>
fullstack is good dharma.
>>
>>106811417
if u got filtered by temperature conversion then ur ngmi. just pick up python and get familiar with it then try k&r. k&r is not an introductory book as much as everyone wants to pretend it is. its much the same with baby rudin in the subject of real analysis (math). everyone pretends its an introduction to analysis when no one actually read it as their first introduction and if they did, they gave up and read tao or abbott
>>
Man, you fucking faggots are annoying. I swear /g/ wasn't so shit even a year ago.
>>
>>106811417
K&R is a shitty book.
>>
File: meh.jpg (42 KB, 659x400)
42 KB
42 KB JPG
You're all so mean!
At least my hello world came out nice.
>>
what kind of autist uses fahrenheit when its just celcius*bugger ?
>>
>>106811795
the put character function is not needful
you have to include the LINUX header standard io
and use the function for print text which is written in the book, it will make for perfect looks
>>
>>106811789
You’re a shitty book.
>>
>>106811470
Kek
>>
>>106811417
I spent years programming in Scratch and then Python before I even knew what a compiler was, so I don't know how hard C is for a beginner. Assuming you are a beginner of course.
>>
>>106811417
I assume you mean you had trouble formatting it correctly.
Honestly that shit still filters me
>>
>>106811818
print is bloat
>>
>>106812533
nevermind, I learned about %N.Nf, I thought you had to do it manually

 
#include <stdio.h>

float conv(float);

int
main()
{

float far = 300;
printf("------------------------\n");
printf("| %-10s | %-7s | \n" , "Fahreneit", "Celsius");
printf("------------------------\n");

for(; far >= 0; far -= 20 ) {
printf("| %10.0f | %7.1f |\n", far, conv(far));
}
printf("------------------------\n");

return 0 ;
}

float
conv(float far)
{
return (far - 32) * 5 / 9;
}
>>
>>106812540
the standard library has so much duplication
>>
>>106812807
good job anon
>>
op do you not know how to find a function from 2 points (0,32) (100,212) what was the difficulty you find the function and then you iterate through some shit
>>
>>106812807
ok now make the table print a function that takes a FILE* argument.
then print to stdout and another file of your choosing. for the lulz.
>>
>>106811470
That is bullshit, nothing about this problem is specific to C.
>>
>>106813860
Fucking wait timer, I will not but a pass.
>>
>>106813869
>polluting global namespace for this
why do cniles exhibit this kind of behavior
>>
>>106813745
Why do that when you can just use IO redirection and tee(1)?
>>
>>106813886
wasting time caring about global name space for 6 lines of code.
>>
>>106813998
All you had to do is put the variable declarations inside the function. I want to understand why cniles do this.
Is it because they think it's "faster" to use CPP than local variables?
>>
>>106814040
variables aren't constant
>>
>>106814075
Oh I see, they do it because C doesn't have constants.
>>
>>106811526
>unbearable reddit stench
>>
>>106814091
Care to tell the class what Reddit smells like? You seem quite familiar with the subject.
>>
>>106814087
It does, however, have a specification.
>>
Celcius is so much better than Fahrenheit holy shit
>>
>>106814147
>Celcius
it's spelled celsius, rajesh
>>
>>106813869
anon your style is gross and inconsistent, and the use of #define is retarded for variables that only get used once. here is a solution that exudes refinement.
#include <stdio.h>

int fahrenheit_to_celsius(const int fahrenheit)
{
return 5 * (fahrenheit - 32) / 9;
}

int main()
{
printf("Fahrenheit\tCelsius\n");
for (int f = 0; f <= 300; f += 20)
printf("%d\t\t%d\n", f, fahrenheit_to_celsius(f));
return 0;
}
>>
>>106814087
>>106814166

Your concerns are outside the scope of the exercise.

>Why didn't you implement database handling just in case someone wants to run the program on one.

no valid use case
closing.
>>
>>106814166
>exudes refinement
>"const int" in a function parameter
>>
>>106814192
does it get modified?
>>
>>106814166
defining constants as constants is good practice, and using defines for constants is good practice in c.
>>
>>106814181
Who are you quoting?
>>
>>106814204
does it matter?
>>
>>106811417
>20 replies
enough, on to the next exercise
>>
>>106814211
or define constants as scoped variables. all the #define does it plug x with y. this is not good practice in C.
>>
>>106814204
It's a function parameter. It's in the signature. But the callers of the function don't care if it's "const" or not because a function parameter can't possibly be modified. So it's just a pointless modifier that screams "I'm a C++ coder trying to write C"
>>
>>106814234
every practice is good practice in C
>>
>>106814242
it is good practice to use the const keyword on things that do not change. technically you never have to use the const keyword. it is just a compiler hint.
>>
>>106814252
it's mostly noise
nothing wrong with it otherwise
>>
>>106811417
it's just making a list right?
what's so hard about this temperature converter
>>
Writing C is not a good practice. It gives you brain damage.
>>
>>106814234
constants are usually defined at the top of the file so that they can be modified without having to read the entire file. Of course they would need a more specific name in a larger project, but for such a short program those names are fine. Yes, defining constants as preprocessor macros is good practice in c. This helps ensure that they are substituted directly and the compiler doesn't attempt to load them from rodata.
>>
>>106814252
>>106814268
No, it's not good practice because a function signature is not the place to talk about the specifics of the implementation of the function.
The signature is for callers, and callers don't care if the function modifies the parameter or not.
How would you declare it in a header file? You have two choices:
>int fahrenheit_to_celsius(const int fahrenheit)
This is schizo, the word const is literally information-free to anyone that's including your header
>int fahrenheit_to_celsius(int fahrenheit)
This is schizo, because the header signature doesn't match the definition

And again we both know the real reason you put const there is because your brain is rotted by C++
>>
>>106814323
you are right there is nothing that can go wrong with c macros, they are good practice and should be encouraged for all variables. to me it makes more sense to make everything a macro, so that way i can just modify the #define in the implementation file.
>>
>>106811417
That's piss easy though. Shit gets real when it asks you to write a rudimentary debugger with only getchar, putchar and printf.
>>
File: 2025-1759815890.png (100 KB, 761x945)
100 KB
100 KB PNG
i'll just be pollutemaxxing. all help is welcome.
>>
>>106814342
regardless of how brain damaged i may be, what is the downside of pedantic usage of const? there isn't one.
>>
>>106814386
use a goto instead of a for loop
>>
#define FIVE 6

where is your god to save you now?
>>
>>106814387
You can go through every header file and write "const" in front of every int parameter. What's the downside? Should you do it?
>>
>>106814386
why not just macro the for loop. seems like a good use of macros to me.
#define loop(i, start, end, inc)                \
for(i = start; i <= end; i += inc)

/// usage
loop(fahrenheit, 0, 300, 20) {

>>
I'm not sure where to start.
A 6 line program filtered you...
K&R is full of 6 line programs that do nothing but show off how bloated printf is...
A bunch of retarded mouthbreathers shilling this slop...

I don't know which one is the worst.
>>
File: .jpg (110 KB, 500x500)
110 KB
110 KB JPG
>>106814342
>callers don't care if the function modifies the parameter or not
I absolutely do care, you retarded lil nigger monkey.
>>
>>106814461
Why?
>>
>>106814511
Because it directly affects performance and complexity of the function and my own code when I'm calling it.
Maybe some function is simpler to implement if it destroys my input data but what if I fucking need that data and I don't want to copy it every time I'm calling the function?
>>
>>106814535
Ah so you don't know C. In C a function can't ever modify an int parameter since it gets a copy.
>>
>>106814566
Tell me I don't know C when you graduate from passing plain ints to functions.
>>
>>106814566
anon the copy is immutable. that is the whole point.
>>
>>106814585
Sure, you can declare the copy immutable, but this is not something the callers should care about, so putting it in the signature is just noise. See >>106814342

>>106814573
Um, okay, you don't know C? You probably think you have some clever counterexample because you don't understand how arrays work
>>
>>106814601
Don't worry anon, in my superior language, arrays can be immutable.
>>
Cniles be liek
>4 character keyword is noise!!1!!!
>>
>>106814609
>*5 character keyword that adds no extra information is noise
yes, it could be one character and still be noise if it adds nothing
>>
// test.h
int foo(const int a);

// test.c
int foo(int a)
{
a += 1;
return a;
}

This code is valid C. Stare at it for a while and you will achieve enlightenment and not attempt to use C++ conventions in a different language.
>>
>>106814647
I'm still gonna use
char const* const str

>>106814652
>2 line function that does fuck all requires whole new compilation unit when it could be static inline in the header
cniles
>>
I'm making my own ISO C compiler (gh/Chubek/lyCC).

I made the type lattice. I'm now making the first revision of the symbol table (pic related).

Opus 4.1 keeps recommending me to add bullshit. I don't know why it is trying to sabotage my poor compiler.

But I've made use of Opus 4.1 by having it summarize the ISO standard.

I had no idea you could do this:

void foo(int b[static 2], int c[const]);


I'm not focusing one a single aspect. I'm jumping around each module.

I'm done with the symbol table for now. Next, I'll have to feed some papers on IRs into Opus 4.1, too see what my IR should look like.

I should read Nora Sandler's book, but I hate No Starch Press. Pajeet-code publishing house. If her book was published by Springer or CRC Press, I would have read it ages ago.
>>
I made a 16-chapter 'dossier' on x86-64 Assembly using Opus 4.1.

https://gist.github.com/Chubek/aa40085d585d474bc26440cf93696f60

I fed it a lot of books. wget it and read it with QuteBrowser.
>>
Protip: don't ask Burger Beckie if she was involved with educational games.
>>
Does anyone know a website where I could upload HTML documents, and people can navigate to it, and it will display the document?
>>
>>106814999
neocities
github pages
>>
>>106815003
I like Neocities better. I don't like Github, and Github pages.

Thanks.
>>
>>106814386
you missed
#define FAHRENHEIT "Fahrenheit"
#define CELSIUS "Celsius"
#define TABULATOR "\t"
#define NEWLINE "\n"
...
printf("%s%s", FAHRENHEIT, TABULATOR);
printf("%s%s, FAHRENHEIT, NEWLINE);

(You don't use chars for newline and tabulator because someone might want to replace them with multiple characters, like four spaces or \r\n.)

Also, you don't return ZERO, you should return EXIT_SUCCESS.
>>
>>106815220
why
>>
I can't stand k&r, I'll read modern c
>>
>>106816499
reading books is for nerds.
real men read code.
and do bootleg courses from reputable talent cultivators
https://github.com/bigpel66/42-cursus/blob/main/circle-00/circle00%20-%20Libft.pdf
>>
>>106814386
typedef int t_fahrenheit
>>
>>106816737
thanks anon this looks pretty good, do u hangout in /dpt/?
>>
>>106817786
not when its a lisp ad thread
or maidnigger central
>>
>>106817786
>>106818583 cont
but im currently posting in there
well, not exactly actively posting, but im answering to my backlog of yous
i had to go afk for a while
>>
>>106811789
>>106811829
Littered with typos on every page and yet every C programmer online treats it like the Quran.
No wonder Bjarne Stroustrup and Rust won.
>>
File: rust-jobs-shrug.png (70 KB, 523x720)
70 KB
70 KB PNG
>>106818671
>yet every C programmer online treats it like the Quran.
>delusions, my only friend
whats up with rust tranies and being mentally ill (moire precisely: schizophrenia)
>pic most rel. thats rust winning
>>
>>106818725
>bot conveniently ignores subtle C++ mention
They're not sending their best.
>>
File: sepples-ripley.png (2.53 MB, 1092x2695)
2.53 MB
2.53 MB PNG
>>106818829
>ill use sepples as umbrella
you gotta try harder
umbrellas dont work too well against boulders
>>
>>106811789
>>106816499
>>106818671
The hate for K&R is just retarded and completely unwarranted. It is not a babby's first programming book. It is still does what it's supposed to do better than any other C book--serve as a quick C primer that gets you up and running with the language in a day or two. You can easily pick up the rest as you go along. As it states in the preface:
>C is not a big language, and it is not well served by a big book.
If you wanna slog through a giant tome and have your hand held, go read King's book.

>Littered with typos on every page and yet every C programmer online treats it like the Quran.
This is just a flat-out lie. Yes, some of the code examples are a little outdated, but thankfully we have these things called search engines, so you can be a big boy and look up what your compiler is complaining about, which is something you're going to be doing all the time in the course of being a C programmer anyway. Maybe you're thinking of the C Answer Book, which is not actually an official answer book and is in fact full of errors.
>>
File: fast-boi-sort.png (20 KB, 564x184)
20 KB
20 KB PNG
>It is not a babby's first programming book.
wtf
then what is it?
t. c-ultist btw
>>
>>106819211
>>It is not a babby's first programming book.
>wtf
It says so right in the foreword...
>>
>>106819184
>>106819211
never read a single book abt c btw
reading books is for nerds. real men read code
(not in its entirety. if i have a question i check the standard. or chat gpt to be honest, chud gpt does it in 95% of cases now. but i also learned before the chatbots
so i mog the chat bots the fuck. garbage in , garbage out , if youre a retard you wont be able to leverage the chatbot. its acorrelation machine. you gotta have an idea of what youre looking for)
>>
>>106819233
complete wtf
where does the following fit in k&r
#define STRINGIFY(target) (t_str *)(&(const struct { size_t size; char text[sizeof(target) + 7]; }){ sizeof(target) - 1, target "\0\0\0\0\0\0\0"})

does it even explain what im doing?
does it even say you can concatenate literals in C?
>>
>>106818671
r*st lost bjarne stepped on it with his long legs
>>
>>106819296 cont
this resolves during compiletime btw
it turn s a literal into a literal struct that contains
-the size
-the string
and pads the literal with 8 zeros.
7 if you consider the null termination of anormal string literal as part of the string object
>>
>>106819211
>then what is it?
It is a tutorial/reference manual aimed at programmers (read: not complete beginners) who want to learn C. Again, also in the preface:

>This book is meant to help the reader learn how to program in C. It contains a tutorial introduction to get new users started as soon as possible, separate chapters on each major feature, and a reference manual.
>The book is not an introductory programming manual; it assumes some familiarity with basic programming concepts like variables, assignment statements, loops, and functions.
>>
File: C-something-2.png (87 KB, 799x799)
87 KB
87 KB PNG
>>106819325 cont of cont
and i did use the chatbots to get to this solution
but its not the solution th at the chatbot gave me, no
i used the ch atbot as a more flexible search engine, and built upon the information it gave me

but is a chatbot worth even a fukken junior?
fuck no
bc a junior at least possesses a fukken brain
>>
>>106819296
I don't know man I just recently read the foreword and it says
>The book is not an introductory programming manual; it assumes some familiarity with basic programming concepts
>>
>>106819347
honestly
its c 101
its sound foundations, but its only foundations
theres also advanced c
otherwise: the interaction of c with its compilers
compiler extensions open a whole new dimension to c

half my shit is force inlined
bc thats how i contain the spaghetti
and i turn c into a high level language, except where i need to go low
but thats compiler-specific
bc the fuckken comittee can pull its fingers out of its ass
>>
>>106814452
is there an alternative to printf for outputting to the screen?
i know dietlibc warns about stdio bloat
>>
File: ai-lmao.png (294 KB, 821x656)
294 KB
294 KB PNG
>>106819400
its still a beginner book
idk, thats what it says on the tin for me
>it assumes some familiarity with basic programming concepts
thats
>some
its not
>expertise
>>
>>106819413
>can pull
*canT pull...
>>
File: overload.jpg (21 KB, 514x280)
21 KB
21 KB JPG
>>106819413 cont
^no tail call no nothing btw
seamlessly integrated into the rest of the code
gcc offers that
fukken msvc, take fukken notes you fukken gorillas fukken vanta fukken black
>>
>>106819490 cont of cont
raises either an error or a warning when something marked force inline cant be inlined
thast gcc
the fukken amateur thing
offers a whole other dimension to c code
fukken shame on you, fukken bantu niggers of the black sort
>>
>>106819441
>its still a beginner book
Only for C, not for programming
>>
>>106819590
ok
this i can agree with
its still very accessible
but also when i read it i knew c
thats why i read it diagonally too
>>
>>106819421
putchar
guess what std it comes from
>>
>>106819766
why read a book about learning c if you already know c
>>
>>106819795
bc im self taught and you never know if you missed something
even if youre college taught, but it comes more naturally when youre self taught
>>
>>106819795
>>106819810
in fact
chances are
like 90%
that if you missed something you wont know it until you stumble upon it one way or another
>>
>>106811417
You won't make it through the rest of krane and resnick
>>
>>106819787
yes, it's from stdio.h
i guess i should have been more clear
is there a way to print and get characters/strings without using stdio.h? asm/syscalls?
>>
>>106814211
the preprocessor is the devil, use it as little as possible. a const int will get optimized by the most stupid of compilers. don't do small functions with the preprocessor either, use the inline keyword. only reasonable usecase for the preprocesor is for #include and MAYBE #ifdefs if you need cross-platform compatibility
>>
>>106820274
there is nothing wrong with using the preprocessor for constants, it's not "the devil" lmao. people who grew up writing c++ have wild fictions in their heads. using function like macros for small generic functions (max etc) is good practice as well.
>>
>>106820315
I've never used sepples in my life, I just prefer using actual language constructs for most stuff since
a) there's usually no benefit on using macros instead
b) it looks cleaner
c) language constructs are easier to debug than the preprocessor
>>
>>106820315
forgot to address your last point, why is using #define max(x) .... better practice than doing inline max(x){....}?
>>
>>106820395
generic over types
>>
File: 1759805234014609.jpg (87 KB, 1113x1200)
87 KB
87 KB JPG
>>106818671
>won
>>
>>106820438
you can work with doubles then
double max(double, double);

inline double max(double x, double y) {
return (x>y?x:y);
}

this works for integers, doubles, floats, chars...
>>
>>106820594
please stop programming in c and consider a career as a javascript programmer.
>>
>>106820644
why? because I actually use the tools the language provides? inline has been part of the C standard since c99, function prototypes have been part of C since ANSI C.
>>
>>106820684
the "tool" of conflating all numeric types with double is also provided by javascript. I think you would rather enjoy it. It even has a general on this board >>>/wdg/. adios!
>>
>>106820594
excellent bait
>>
>>106820711
>wants generic
>i offer generic
>go 2 javascript!!!
retard
>>
>>106820735
>doesn't understand c
>i offer language more his speed
>u retard!!!!
>>
>>106820594
you should use an epsilon when comparing floats really
>>
>>106820743
sorry then, keep using your glorified string replace tool thingy
>>
>>106820765
i and the entire professional c programming community will, thank you very much. you enjoy your scripting language
>>
>>106814133
But it doesn't have a reference compiler.
>>
>>106811806
it isn't just a shrimple multiplication
>>106811470
I doubt OP was talking about the formula, dingdong. to be fair I dont know either >>106814040
0/10 bait
>>
>>106814999
what a waste of numbers and oxygen
host your own static file server you absolute mongrel
>>
>>106820684
>c99
cringe
>c89
uhh, based‽
>>
>>106816758
fahreheit_t
PLEASE
>>
>>106821152
fahrenhei_t
>>
File: fahrenhei_t.png (819 KB, 1200x1200)
819 KB
819 KB PNG
>>106821152
>>106821351



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