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


File: 1_tEDdG7Hr_Ob1RxMj-fM-cg.png (1.51 MB, 1000x1333)
1.51 MB
1.51 MB PNG
Learning C is actually really easy. You can learn the ins and outs of the whole language in a few weeks. .... until you try to do something useful with it, in which case it becomes complicated beyond comprehension.
>>
>>101560439
sudo rm -rf xx*
>>
File: Zero.png (93 KB, 500x500)
93 KB
93 KB PNG
C is kinda comfy to program in, but I prefer Zig.

Although Zig tries to be "simple" it actually is pretty complex.
>>
>>101560418
This shit is not fun
bool is_substring(char *check, char *string)
{
int slen = strlen(string);
int clen = strlen(check);

int end = slen - clen + 1;

for (int i = 0; i < end; i++)
{
bool check_found = true;
for (int j = 0; j < clen; j++)
{
if (check[j] != string[i + j])
{
check_found = false;
break;
}
}

if (check_found) return true;
}
return false;
}
>>
>>101562719
Explain why you are doing full comparison and not a rolling hash across the search string.
>>
File: johnCarmackCopyPasta.png (65 KB, 1841x179)
65 KB
65 KB PNG
>>101560418
>until you try to do something useful with it, in which case it becomes complicated beyond comprehension.
>>
>>101563030
Not him but what do you gain from using a hash? The time complexity of doing a direct comparison is O(n).
Using a hash would be O(n^2) because you would have to check each character in the haystack as many times as there are characters in the needle, wouldn't you?
>>
It's the computers that are complicated, not the language. C just doesn't hide the reality from you.
>>
>>101560418
>Incel discovers he actually needs to learn the libraries his OS provides in order to make functioning programs
Lmao
>>
>>101560418
just read the documentation?
>>
>>101563078
A rolling hash you retard. That's one with the property that you can move it in a window. You hash the substring you're looking for and then roll the window across the search text and only check matches. Do you not know what rabin-karp is?
>>
Is it time yet? probably not
>>
>>101562452
I feel like Zig just took the reinvent wheel meme to the next level.

Reading and writing to stdin with C is very easy, now do the same with Zig and you need to setup write/read buffers and all that jazz.
>>
>>101564234
Irrelevant. Memory safe language. It's just better.
>>
>>101563085
>C just doesn't hide the reality from you.
>inline doesn't actually inline
Nice fucking meme.
>>
>>101564234
Try writing a serious program in C that reads from/writes to standard i/o... some things you'll notice:
>libc buffering is incompatible with async i/o
>ok, turn off libc buffering
>now your program is async but slow as shit
>write your own buffering mechanism
>fuck
And this isn't just i/o either.
>want strings?
sorry, C strings are fucked, write your own.
>want encoding support?
sorry, C locales are fucked, write your own. (and hope no dependency of your EVER depends on that global, non-thread-safe state.)
>integer parsing, sorting, env vars, allocators, ...
sorry, all fucked! write your own.

C is OK if you're fine with reinventing the wheel every time you do something slightly more complex than hello world. But it could be so much better if only it had usable standard interfaces instead of all this suboptimal broken shit somebody added 30 years ago without fully understanding the problem domain. (Or 40 years ago, understanding the problem domain but making a compromise to make it work in an environment 10000x less powerful than my toaster.)
>>
>>101564249
I thought zig wasn't memory safe?
>>
>>101563085
>It's the computers that are complicated, not the language. C just doesn't hide the reality from you.
C hides reality and replaces it with something completely different. The complexity of C has nothing to do with your CPU. Your CPU doesn't have if, while, for, malloc, free, printf, scanf, puts, files, locales, #include, #define, etc. The complexity of your CPU has nothing to do with C. C doesn't have registers, flags, instructions, interrupts, paging, segmentation, address spaces, virtual machines, vectors, I/O ports, etc.
>>
>>101562452
>Although Zig tries to be "simple" it actually is pretty complex.
Is that so? Rust seems to be the same.

>>101564234
So it's like Java?

>>101562719
strstr is usually optimized better in libcs.

>>101564574
C actually has a sane and efficient default.
Yes, most things in C and especially libc are legacy, because the C standards committee doesn't want to push C forward. They're only adding dumb incomprehensible idiocy like _Generic.
>>
>>101564574
>write your own
there's something in between writing your own everything from scratch and pulling in an entirely new language, namely using an existing library. Since every nulang insists on making endless retarded design decisions this is really your only choice if you want a sensible interface anyways
>>
>>101562719
C is about learning to have fun on your own
while(*check) if(!strcmp(check++, string)) return 1;
return 0;
>>
>>101564574
>But it could be so much better if only it had usable standard interfaces instead of all this suboptimal broken shit somebody added 30 years ago without fully understanding the problem domain.
There were already languages with better strings like BASIC, PL/I, Algol 68, and Pascal which are also faster than C.

>(Or 40 years ago, understanding the problem domain but making a compromise to make it work in an environment 10000x less powerful than my toaster.)
If that's what they were doing, it would be more like BASIC and FORTRAN, not like C. C was less efficient than other languages at the time. It took about 20 years for computers to catch up to the point that the inefficiency of C compared to assembly and FORTRAN didn't matter as much.
>>
>>101565556
Should be strncmp or memcmp with strlen(string).
>>
>>101564574
skill issue
>>
>>101565719
You're a midwit, but it's ok because even midwits can learn C.
>>
>>101565817
No. Your strcmp will only check for string at the end of haystack.
>>
>>101564574
The whole point of C is that it contains only what is necessary. If you want a pointlessly huge library of garbage, then just go link against GNOME's glib or something.
>>
>>101565556
Why are you iterating through the needle (check) and not the haystack (string)?
>>
>>101560418
Give me a task to make "something useful" with C, I'll give it a try if it's something that can be done in an evening
>>
>>101566452
Historical challenge: Make a program that outputs the same text as the source of the program.
>>
>>101566247
>it contains only what is necessary
But half that post is about getting rid of worse-than-useless standard C garbage
>>
>>101560418
i don't think there is any point in learning programming if you don't understand how computer systems work, and this is especially true for languages with low abstraction, the closer it is to machine code and the memory ranges of the hardware, the more it requires the operator to understand what he is doing.
there is no shorter or more convenient way if you don't understand how data structures and operating systems work either take the time to learn it or don't bother with programming.
>>
>>101566725
True. C is considered portable assembly for a reason.
>>
File: GTPbR3LaAAAYNpf.jpg (397 KB, 1058x2048)
397 KB
397 KB JPG
>>101566725
This is only true to a certain level. I've seen employed people work with C++ like it was Python, linking libraries and nesting functions with assumed complete freedom and disregarding data structures entirely, not even knowing what a linked list is.
If Crustacean syntax wasn't verbose garbage that gets tiring to type even with auto complete, libs weren't broken across, compiling times weren't absurd and the language didn't try to actively work against you whenever you have to do something actually useful then I'd far prefer it. As it stands, though, Babel is crumbling.
>>
>>101562452
Nig sucks
Nig will never be C++
>>
>>101560418
Is that book still relevant?
>>
>>101562719
pfft, why run strlen when you can check the running pointer for being different to 0
>>
>>101560418
>until you try to do something useful with it, in which case it becomes complicated beyond comprehension.
Low IQ take. Programming in C is easy and comfy.
>>
>>101567975
It's meant to be like C but not outdated. Every usecase of C could be written in assembly if it's for "performance". Zig replaces C.
>>
>>101562719
so make it fun
int is_substring(const char *check, const char *string)
{
const char *p, *q, **pp = malloc(strlen(check) * sizeof(const char *));
for (p = check, q = check + 1, *pp = NULL; *p && *q; q++) {
if (*p == *q)
pp[q - check] = pp[p - check];
else
pp[q - check] = p;
while (p && *p != *q)
p = pp[p - check];
if (!p)
p = check;
else
p++;
}
for (p = string, q = check; *p && *q; p++, q++) {
if (*p == *q)
continue;
if (!(q = pp[q - check]))
q = check;
else
--p, --q;
}
free(pp);
return !*q;
}
>>
File: ==.png (722 KB, 1380x1791)
722 KB
722 KB PNG
>>101560418
>Learning C is actually really easy.
No, it's not. There are a lot of pitfalls in C that are not so obvios to newbies-
>>
File: andrew.png (59 KB, 320x320)
59 KB
59 KB PNG
>>101562452
Kys.
>>
>>101560439
i'm going to assume this is some computer bricking conversation to some del system32 or whatever and report it for illegal post
>>
>>101572631
He was kidding. You know that.
>>
>>101572750
It makes 99 empty files. Easy to delete with a wildcard or even just ctrl shift click selection.
>>
>>101564574
C is just a less shitty assembler for PDP-11
>>
>>101572550
i’m sorry but if you can’t understand why
>set X equal to Y
is not the same as
>see if X is equal to Y
you are too low IQ to use a computer.
>>
>>101572949
I was talking about UB, basically you can't perform any operation on signed numbers (there are other cases of UB).
>>
>>101564574
True, the standard library functions are mostly shit (primarily the string functions) and shouldn't be used in real applications (besides memcpy, memmove, memset, malloc, free, etc.)
C needs an overhaul (without turning it into C++), mostly of its standard library, maybe Zig will be that since C can't really be changed without breaking a ton of shit.
>>
>>101573093
It will. C is for Chalked. Zig is just superior.
>>
>people are finally realizing C++ is literally just a better C
About time. Thankfully I moved on to Rust. Enjoy your AIDS, losers.
>>
>>101573018
why would i want it to do things i don’t tell it to lol
>>
>>101572550
you can do this in any fucking language retard
>>
>>101572775
you're not gonna gaslight me
>>
>>101573271
Not really. Only shitty ones that make mutations, expressions for some retarded reason.
>>
>>101564234
>now do the same with Zig and you need to setup write/read buffers and all that jazz.

That's because it's designed to be verbose, showing/allowing for full control over your program.
>>
>>101573429
What do you sweaty nerds not understand? I DON'T WANT FULL CONTROL. I want functions to do all the things I need that I can bash together without ugly symbols like ; | : ~ all over the place. The job of you smelly dweebs is to be building my python library so I can actually make something useful without wasting my precious time.
>>
>>101573479
And then you realize what side effects are and realize that there aren't a lot of tools to control them thus why people prefer inversion of control, sans I/O, lately effects systems and all of those other meme words and some other type system stuff.

C is just dog shit, especially because libc is broken by design, worse because it's type system basically doesn't exist. You're pretty much better off just using C++2x and moving on with your fake and gay life but you're too retarded for it.
>>
File: 76510681.gif (13 KB, 190x200)
13 KB
13 KB GIF
>>101573512
No idea what you're saying, python just works.
>>
>>101573512
>it's
opinion discarded
ESL detected so you're likely brown and have an iq in the double digits
>>
File: 1717375303341554.jpg (13 KB, 225x225)
13 KB
13 KB JPG
The Cnile is immunized against all dangers: One may call out his segfaults and awful build systems and dependency management, it all runs off him like water off a raincoat. But tell him to parse some yaml with a few lines of code and you will be astonished at how he recoils, how injured he is, how he suddenly shrinks back: "Don't need to, I'm unemployed!"
>>
>>101560418
Then you didn't correctly implement each program in the c book. Reread the problems and don't use syntax and functions that weren't introduced yet.
>>
File: kr.png (57 KB, 1288x885)
57 KB
57 KB PNG
no serious alternative
it'll run the world for another 50 years
>>
>>101560418
>You can learn the ins and outs of the whole language in a few weeks
you should be able to learn the ins and outs of C in a day or two. its really not very complicated whatsoever because there isn't a whole load of abstraction.
>>
>>101574749
But you can still do that?
>>
>>101574749
>no serious alternative
There's no serious alternative to C for buffer overflows and backdoors.
>>
>>101574989
>buffer overflow
Write code that doesn't have it
Use a compiler flag that gets rid of the explioit
>backdoors
Don't accept backdoor prs. Carefully check anything that branches.



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