[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Newfag here. What do you guys think the best book for learning

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 174
Thread images: 10

File: 9780131103627.jpg (63KB, 491x648px) Image search: [Google]
9780131103627.jpg
63KB, 491x648px
Newfag here. What do you guys think the best book for learning C?

>inb4 C the programming language
>>
The standard.
>>
>>59387797

reddit.com/r/programming
>>
>>59387797
This book:
https://www.amazon.com/Programming-Rust-Fast-Systems-Development/dp/1491927283
>>
Why do you wanna learn C, dude? Are you new in programming world?
>>
>>59388730
need to learn it for work
>>
>>59387797
Your pic.
Not even memeing.
>>
>>59388930
i was looking for a different book
>>
>>59387797
C is a disservice to intelligent programmers. It has almost 0 features that a modern and intelligent programmer uses to be productive. Since C is such a timesink, it's popularity is falling more than any other languages in the market.
C is dying and it should die ASAP. C programmers are actually retards in general. C is a small language to grasp, exactly the kind of shit that makes things retard friendly.
C has no advanced features like C++ does.

But as a newfag you are kinda in the right direction. C is for newbies. Think of it this way:
During ancient times, counting to 10 was a big deal and a person who could count to 10 was considered to be "wise".

Fast forward a few century counting to 10 is so trivial we teach this to toddlers. Now toddlers appreciate the vast "knowledge" of counting to 10 while matured brains are busy with modern technologies.

C is from stone age and the people who still preach it is like overgrown toddlers that can't learn advanced things.
C doesn't have delegates
C doesn't have resizable arrays
C doesn't have strings
C doesn't have string concatenation
C doesn't have namespaces
C doesn't have exception handling
C doesn't have closures in the standard
C doesn't have unit tests
C doesn't have Function overloading
C doesn't have memory safety of any kind
C doesn't prevent memory exploits and has no bounds and runtime checks
C doesn't have dynamic method loading/creatin
C doesn't even have generics and templates
C doesn't have meta programming
C doesn't have mixins
C doesn't have higher order functions
C doesn't have contract programming
C doesn't have inner classes
C doesn't have function literals
C doesn't have array slicing
C has a very limited support for implicit parallelism
C doesn't even have string switches

C is a cancer that plagues the modern industry. If you want guaranteed memory exploits and security vulnerabilities in your program with timesink development period then use Assembly, not C.
>>
>>59389366
C is excellent for fairly low level programming and portability. There are billions of people on this planet and not all of them have all of the requirements that you do.
No one is going to write a microwave driver in Javascript.
>>
>>59389366
>resizable arrays
What is a pointer?
>no strings
What is a char array?
>no string concatenation
What is strlcat() strncat() and strcat()?
Also:
printf("string" " " "concatenated);

>no exceptions
setjmp() and longjmp()
>unit tests
Make your own.
>generics
void * is all you need.
>meta programming
AKA making code unusable and unreadable.
>memory safety
>memory exploits
>runtime checks
AKA intelligence
>>
>>59389679
printf("string" " " "concatenated");
>>
>>59387797
Pointers on C by kenneth Reek.
>>
>>59389679
>>59389679
>what is pointer
Not a resizable array
>char array is strings
Yeah, char iteslf is an int from the ASCII table
>printf("string" " " "concatenated");
That's not concatenation operator
string3 = string1~=String2 is string concetanation
>setjmp() and longjmp()
Wso where is try catch and finally blocks?
>Make your own unit test.
How about I use a lanugage that has these already
>void * is all you need.
No I need powerful templates
>AKA making code unusable and unreadable.
A c tard doesn't understand the need of meta programming
>AKA intelligence
100 out of 100 C developers produced hundreds of security bugs with that mentality

C is a fucking Cancer and it HAS to die.
>>
>>59389589
If I need to write a driver I would pick ASM over C any day any time. Why are c tards so afraid of JS when it clearly has it's own niche purpose just like C itself.

Although I would argue that C has no place in the modern world. Either use ASM or C++. C is an awkward uselessness in the middle
>>
>>59387797
C Programming: A Modern Approach by K.N. King.
>>
>>59389884
>what is pointer
>Not a resizable array
Yes it is. You can put a buffer of whatever on the heap and access it like an array.
Another anti-C shill who doesn't know shit about C.
Arrays are pointers.
>char array is strings
>Yeah, char iteslf is an int from the ASCII table
And? A string is an array of char's. Saying that isn't a string is retarded. That is the DEFINITION of a string.
>printf("string" " " "concatenated");
>That's not concatenation operator
>string3 = string1~=String2 is string concetanation
You want operator overloading, not string concatenation. String concatenation has nothing to do with operators you fucking web """"dev"""" trash.
>setjmp() and longjmp()
>Wso where is try catch and finally blocks?
In a cancer wing.
>Make your own unit test.
>How about I use a lanugage that has these already
Please do. C doesn't need or want you.
>void * is all you need.
>No I need powerful templates
AHAHAHAHAHAHAAA
>AKA making code unusable and unreadable.
>A c tard doesn't understand the need of meta programming
Oh I understand it, and that's why I don't want to touch it with a ten foot pole unless I absolutely have to.
>AKA intelligence
>100 out of 100 C developers produced hundreds of security bugs with that mentality
Shitty programmers produce shitty code, no matter what language. (You) being in that demographic obviously wouldn't understand this.

>C is a fucking Cancer and it HAS to die.
You first.
>>
>>59389918
No.
C is a middle ground between ASM and C++.
Kernels fit perfectly here.
Try and maintain kernel with modern features that is also written in ASM.
If you will kill yourself within days.
>>
>>59389995
>Yes it is. You can put a buffer of whatever on the heap and access it like an array.
That's not resizable array. No wonder C has damaged your brain to the point where you do not understand array.allocate(N)
>Arrays are pointers.
Everythig is
>and?
So WHY THE FUCK DO YOU NEED CHARS WHEN YOU GOT MOTHERFUCKING INTS TO REPRESENT CHARS?
>operator overloading
Does it exist in C? Yes?
>try-catch-finally doesn't exist
Because C doesn't have exception handling
>Doesn't know generic programming
Stick to your toddler tier if else while for loops programming, brainlet c tard
>Oh I understand it
No you don't. Because C simply has no meta programming
>Shitty programmers produce shitty code
>Linus is a shitty programmer
I like the mental gymnastics of a backward ass drooling c tard and how angry they get when someone points out what a massive piece of shit C is
>>
>>59390153
>That's not a resizable array
>Everything is a pointer (including arrays)
>pointers can be resized
Nice logic there.
You should get a refund from your Code Bootcamp.
>So WHY THE FUCK DO YOU NEED CHARS WHEN YOU GOT MOTHERFUCKING INTS TO REPRESENT CHARS?
It's shorter.
Kind of like the difference between
char str[] = {'n', 'i', 'g', 'g', 'e','r', '\0'};

and
char str[] = "nigger";

>operator overloading
>Does it exist in C? Yes?
No, and for good reason.
It is abused by shitty programmers to obfuscate code. (You) apparently are a prime example.
>Because C doesn't have exception handling
The behavior can be emulated with setjmp() and longjmp(). Why you want hidden goto's everywhere is beyond me. If you want them so bad don't use C. It's not rocket science.
>Stick to your toddler tier if else while for loops programming, brainlet c tard
For 99.9% of programming that's all you need.
But okay, continue masturbating over your Code Bootcamp certificate.
>No you don't. Because C simply has no meta programming
>implying C is the onlyl anguage I use
No. I use other OOP languages with the """"features"""" you describe and have seen firsthand how they are abused.
>Shitty programmers produce shitty code
>Linus is a shitty programmer
No he isn't, and to wonder what twisted logic you used to imply that I implied this in any way proves your IQ is in the double digits.
>>
>>59389918
Actually although C was my first love, I now am a Javascript developer. I just said you wouldn't use it for a microwave.
Where is all this unfounded hate coming from?
It does have a place, ASM is not good for writing structured programs or for portability.
>>
>>59390283
>char str[] = "nigger";
>shorter
That ain't short, this is short: string = "c tard";
>No, and for good reason.
Yes, C is not growing, it's just a dying tumor. Does it even have lexical closures?
>string1~=string2 is (((abuse)))
Wow, c tard you trully are showing your c tardation.
>For 99.9% of programming that's all you need.
Only if your piece of shit language is an insult to people with IQ higher than 20 it is

Dumb shit c tard just fuck off and cry in the corner while developing your non existent kernel
>>
>>59390346
>C
>Portability
>Good for sturcutes
I think you hit your head pretty bad
>>
C is so simple and void of functionalities it feels like an insult to write C programs
>>
OP here. I didn't know starting a thread like this would cause an argument like this. Regardless, I will learn C and C++ from what I've gathered
>>
>>59387797
ITT: unimportant retards arguing over pointless shit that most career developers don't give a flying fuck about. None of you are the next paragon of software, nine if you will do anything worthwhile or to further the creation of software, you're all nobodies who won't be remembered
>>
>>59390365
Actually, I was referring to structured programming, as in the use of blocks to write code. Assembly language does not use blocks. Check out some articles if you want to know more, it's actually quite interesting.
http://www.informit.com/articles/article.aspx?p=30303&seqNum=2
Brainfuck's ancestor was actually written as the first proof that structured programming was Turing complete.

As for portability, I'm referring to the fact that assembly language is architecture specific, whereas C, being a compiled language, is not.

I can see how you'd get confused, what with the popular definitions of these terms.
>>
>>59390425
Not with that attitude!
>>
>>59390441
>Compiled languages are portable
?
>>
>>59390456
I hate to quote wikipedia, but it has a good summary on this:
>Each assembly language is specific to a particular computer architecture. In contrast, most high-level programming languages are generally portable across multiple architectures but require interpreting or compiling.
>>
>>59390351
>his posts get shorter
Topkek
>this is short: string = "c tard";
typedef char * string;

Not that any non-retard would want to do that.
>Yes, C is not growing, it's just a dying tumor. Does it even have lexical closures?
Next standard will.
C will last longer than any of your meme languages.
>>string1~=string2 is (((abuse)))
Wow, c tard you trully are showing your c tardation.
If you can't see how operator overloading can be abused, you probably don't even program.
Don't use C if you want operator overloading.
>Only if your piece of shit language is an insult to people with IQ higher than 20 it is
What is being turing complete?
More seriously, why is the backbone of everything written in C? All your meme language interpreters are written in C, all your meme langauge compilers were written in C at least at first.
Really makes you think.
>>59390425
>look at me im above everyone else because i dont have an opinion xdd
>>
>>59390392
Ignore these ballbags, literally any site these fuckin months mock will point you in a better direction. You want good advice in this? Hit up Reddit
>>59390451
Yeah, that's the issue, my lack of positivity towards this festering cum bucket of a board and cunts that visit it. Thanks doctor Phil was having an existential crisis before you chipped in there
>>
>>59390504
>Yeah, that's the issue, my lack of positivity towards this festering cum bucket of a board and cunts that visit it. Thanks doctor Phil was having an existential crisis before you chipped in there
Forget that, have a better opinion of yourself.
>>
>>59390489
Took you a while to take that damage
>his posts get shorter
what?
>typedef char * string;
-you need a screwdriver to drive the screw in
c tard: ok let me build that screwdriver
normal person: done already

>creating typedef for things trivial as strings
LMAO and this is the c tard that doesn't like meta programming and templates

100 bucks say he'd defend c even if it didn't have macros

>Next standard will.
AHAHAHAHA MAYBE LIKE 25 YEARS LATER WHEN C GOES EXTINCT GCC WILL GET IMPLEMENT "CWHATERVERTHEFUCKYEAR"
>If you can't see how operator overloading can be abused,
That's not "abusing" that's using, you can call the grapes are sour because you can't have 'em

>What is being turing complete?
Brainfuck is turing complete. Fuck off and use brainfuck because anything but brainfuck are bloats

C++ doesn't need C in any cases and neither does D or Rust.

>C is the "backbone"
Because evolution exists. No one uses FORTRAN anymore as much and no one will use C in the near future. LLVM and GCC are already written in C++

Fuck C and your feelings, c tard. Commit suicide with your dying shit languagelet
>>
>>59390527
I've got a great opinion if myself, it's the subhumans who should've been a stain on a mattress that endlessly debate the minutae of C every fucking day on this board that I look down on
>>
>>59390611
You should concern yourself with things you can control then. You will be happier.
>>
Every single time,
Every single fucking time I see C codes I cringe visibly and I feel disgusted enough to puke. C gives me the hardes cringes
>>
>>59390631
I'm happy enough as is, what would elevate me to fucking Nirvana would be less retards like most of those in this thread. It's embarrassing that it's easier and more productive to turn to Reddit for tech discussion than /g/
>>
>>59390657
I was talking about this earlier
>write a program in C that takes any number of arguments as strings, and returns the pointer of the concatenated arguments
C:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>

char *concat(size_t n, ...)
{
va_list args;
va_start(args, n);

// Find total length of output string

size_t len = 0;
va_list iter;
va_copy(iter, args);

for (size_t i = 0; i < n; ++i) {
const char *str = va_arg(iter, const char *);
size_t n = strlen(str);

// Overflow. Only sensible option is to fail.
if (len >= SIZE_MAX - n)
return NULL;

len += n;
}

va_end(iter);

// Null terminator
++len;

char *res = malloc(len);
if (!res)
return NULL;

char *ptr = res;
for (size_t i = 0; i < n; ++i) {
const char *str = va_arg(args, const char *);

// Using the non-standard (but POSIX standard) stpcpy,
// so we aren't constantly rescanning over the string
ptr = stpcpy(ptr, str);
}

va_end(args);
return res;
}

int main()
{
char *ptr = concat(4, "Hel", "lo, ", "Wor", "ld!");

printf("%s\n", ptr);

free(ptr);
}


as opposed to either
def concat(*s): return ''.join(s)

or
import std.stdio;
void main(string[] args){
string result;
foreach(arg; args[1 .. $]){
result~=arg;
}
writeln(&result);
}

God I hate C
SO
FUCKING
MUCH
>>
>>59390607
I can just imagine some fat jobless fuck, who just got through his shitty Code Bootcamp frothing at the mouth with this post.
>-you need a screwdriver to drive the screw in
>c tard: ok let me build that screwdriver
>normal person: done already
Because typing one line, or just typing a few extra characters, is so difficult.
Confirmed for having never programmed anything.
>AHAHAHAHA MAYBE LIKE 25 YEARS LATER WHEN C GOES EXTINCT GCC WILL GET IMPLEMENT "CWHATERVERTHEFUCKYEAR"
You are not making sense here, but people like you have existed for a long time.
C is still here. C is still being used. I'm (not) sorry if that triggers you.
>C++ doesn't need C in any cases
Many functions in C++ come from C you fucking retard.
>neither does D or Rust
AHAHAHAHHAHAHAHA
What is libc.so? Fucking retard.
>C is the "backbone"
>Because evolution exists. No one uses FORTRAN anymore as much and no one will use C in the near future. LLVM and GCC are already written in C++
GCC is more like a C project, it barely uses C++ features, and it was all C not too long ago, bad example.
Most libraries and kernels still use C, and will always use C. Most of your meme languages call out to C or C++ libraries
>Fuck C and your feelings, c tard. Commit suicide with your dying shit languagelet
"No"
>>59390657
>>59390737
Nice copypasta CIA nigger.
>>
>>59390737
>Has a GC
>As a systems language
Dropped
>>
>>59390392
There are 40 posts and 12 posters

It's one guy who's trying to force a meme that C is bad
>>
>>59390782
>Because typing one line, or just typing a few extra characters, is so difficult.
A ctard has to shit all over the source files to hack together operaotr overloading and generics while other people have done their job. Cry harder, autistic fucktard
>You are not making sense here, but people like you have existed for a long time.
There is no lambda or closures in standard c, autist
>Many functions in C++ come from C you fucking retard.
yea, the if while for loops that toddlers limit themselves into
C++ crashes the fuck out of C in every single way possible
>GCC is more like a C project
It's written in C++ and so is LLVM. Keep crying, autistic c tard NEET
>>
>>59390737
wtf I hate C now
>>
>>59390737
The C example has to come from a bad programmer, right? I mean it's pretty bad
>>
>>59390932
>I mean it's pretty bad
Why is it bad?
>>
>>59390942
it looks like too much work in comparison, an unintuitive too
>>
>>59390892
>his posts just devolved into calling me an autist and a c tard
>he's not making any points
Nice talking to you. CIA nigger.
See
>harmful.cat-v.org/software/c++/linus
>>59390737
According to the problem
>write a program in C that takes any number of arguments as strings, and returns the pointer of the concatenated arguments
Why would you use varadic args nigger?
Just iterate over argv.
>>
>>59390942
>Why is it bad?
Because it's fucking C
>>59390932
No, C programs are inherently disgusting and ugly like that
>>
>>59390953
>too much work
In a language where you manage your own memory, that's sort of what you need to do.
Other languages are doing probably dozens of allocations behind your back.
The C example only does 1.
>unintuitive
How? The va_list stuff kind of shits the function up, but that's what has to be done if you're using variable arguments.
It goes through some pretty logical steps:
- Find the length of the string
- Allocate the string
- Copy into the string
>>
>>59390962
>Just iterate over argv.
Let's see your beautiful code, anon
>>
>>59390782
>Because typing one line, or just typing a few extra characters, is so difficult.
An absolutely moronic appreciation of programming and engineering in general.

The problem isn't just typing more, the problem is being more convoluted for the sake of being more convoluted, allowing the possibility of bad things to happen for no advantageous reason and the redundancy of going out of your way to do something that can only be done one way.

>C is still here. C is still being used. I'm (not) sorry if that triggers you.
"People are doing it" doesn't mean it's a good idea

It's on the way out, though. We can and will eliminate needless complexity wherever it is, and for good reason.
>>
>>59390989
>It's on the way out, though
Just because you said it, it doesn't mean that it's true.
There is still no viable language for replacing C.
>>
>>59390978
>Find the length of the string
>- Allocate the string
>- Copy into the string
timesink
-get the strings
-join them
-return the joined string's pointer

boo fucking hoo
>>
>>59391010
>join them
Define how this is done.
>>
>>59390962
>he's not making any points
see >>59389366
Idiot drooling autist
>>
File: yN82m.png (366KB, 1366x768px) Image search: [Google]
yN82m.png
366KB, 1366x768px
>>59391000
>There is still no viable language for replacing C.
Should we tell him?
>>
>>59391023
new string = string1string2
>>
>>59391030
Rust is not a viable replacement for C.
C++ is not a viable replacement for C.
D is not a viable replacement for anything.
>>
>>59391044
i.e. "I have no idea how memory works".
>>
>>59391045
C++ rust and D are more than viable to replace C. Maybe you need to understand this is 2020
>>
>>59391054
What's your point? Why do I need to manage memory myself for doing what I was told to do?
>>
>>59391058
You clearly don't understand C, or why it's popular.
I'm not even going to bother arguing with you anymore. You can't convince the wilfully ignorant.
>>
>>59391045
>Rust is not a viable replacement for C.
It's a C styled language that offers all the control while being safer, is more advanced and is faster

Let's hear how contrived you get trying to justify why it's not a replacement for C
>>
well CIA nigger respond to >>59390987
>>
>>59391070
>or why it's popular.
Yes people found a better language than FORTRAN

Tell me why I need to manage memory myself to join two fucking strings?
>>
>>59391045
The way you write rust, memory management is an automatic by product, without a GC. It's an upgrade from RAII
>>
>>59390942
The problem could have been solved in a more efficient less retarded way.
This """example""" was coughed up by a CIA nigger.
>>59390987
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
int i;
size_t n = 0;

if (argc < 2)
return 1;

for (i = 1; i < argc; i++)
n += strlen(argv[i]) + 1;

char *ptr = calloc(1, n);
if (!ptr)
return 1;

for (i = 1; i < argc; i++)
ptr = strcat(ptr, argv[i]);

puts(ptr);

free(ptr);

return 0;
}
>>
>>59391123
Is this the cleanest you can come up with?
Literally NO match for
r

import std.stdio;
void main(string[] args){
string result;
foreach(arg; args[1 .. $]){
result~=arg;
}
writeln(&result);
}
>>
>>59391123
Was that supposed to be more convincing in any way?

C people are really mentally ill
>>
>>59391139
It is much cleaner than >>59390737
I could re arrange a few things to make it look nicer, but if you can't understand what my code does, then you are fucking retarded and should not be allowed near a computer.
It's probably much faster than your D example.
>>
>>59391167
I understand how your shitty toddler ptr trickzz workds, it's not rocket science. Problem is"
a: Your code makes me puke
b: There is no point of managing memory for a function that literally joins two strings
c: C is a fucking timesink
>>
>>59391167
Your code doesn't print a pointer, it prints the joined string
>>
>>59391193
>it makes me puke REEEEE
Okay? Doesn't really matter to me.
>there is no point in managing memory for a function that literally joins two strings
....
You do know that D, Rust, C++ and virtually every higher level language puts strings on the heap right?
>i understand it
>calling it ptr trickz
>not knowing how strings work
>not knowing the difference between the stack and the heap
No you don't lol.
>c is a fucking timesink
That didn't take me that long to make.
>>
>>59391271
see >>59391257
>>
>>59391123
>>59391139
What a fucking joke.
>>
>>59391257
>it doesn't print the pointer it prints the joined string
Brainlet detected.
You do know what a string is right?
If you want the address then
printf("%p\n", ptr);

CIA nigger.
>>
>>59391292
>dmd
You do realize you use ldc, right?
>>59391305
What the fuck you fucking low IQ autistic trash? It literally prints the string, not the address you dumb fucking retard with chronic down syndrome
>>
>>59391335
>its another anti c shill that goes into a fit of rage when he gets btfo episode
>>
>>59391335
It's still fucking garbage.
>>
>>59391362
Your code prints a fucking string you dipshit c tard see your abomination >>59391123 very carefully
>>
>>59391392
What makes it "garbage", archtoddler?
>>
>>59391418
75 allocations, 4 of them leaked, 60KB memory for such a simple program.
If this is how it handles trivial programs, I don't even want to see how it handles non-trivial ones.
>>
>>59391397
No it deference a pointer to an array of characters.
Try again brainlet.
If you want the actual pointer (why?) see >>59391305
>>59391418
>that disc usage
D: 180K
C: 12K
>that 60kb allocation
>only 1036 bytes allocated for C
Really makes you think.
>>
>>59391433
>60KB memory
What? is that supposed to be satire?
>>
>>59389366
>C doesn't have delegates
>what are pointers to functions?
>C doesn't have resizable arrays
>what is malloc() and free()?
>C doesn't have strings
>what is char *?
>C doesn't have string concatenation
>what is string.h?
>C doesn't have namespaces
>what is scope and not being a retard?
>what is appending a name space tp a variable name if you need it that bad
>C doesn't have exception handling
>what is setjmp() lngjmp() and goto
>C doesn't have closures in the standard
>what is an intentionally small standard with the ability to implement what is needed?
>C doesn't have unit tests
>what is writing your own tests?
>C doesn't have Function overloading
>what is a dangerous "feature" that can be implemented with stdarg.h anyways?
>C doesn't have memory safety of any kind
>what is checking array bounds?
>C doesn't prevent memory exploits and has no bounds and runtime checks
>what are things that have been implemented?
>C doesn't have dynamic method loading/creatin
>what are structs with pointers to functions?
>C doesn't even have generics and templates
>C doesn't have meta programming
>C doesn't have mixins
>C doesn't have higher order functions
>C doesn't have contract programming
>C doesn't have inner classes
>C doesn't have function literals
>what are huge waste of times?
>C doesn't have array slicing
>what is pointer arithmitic and loops?
>C has a very limited support for implicit parallelism
>what are libraries?
>C doesn't even have string switches
>what is making an array of strings, searching it for your string, then switching to the array value?
>>
>>59391457
>Contract programming
>"waste of time"
HAHAHAHAHAHA
>>
>>59389884
>That's not concatenation operator
>if you don;t use my stupid operator you don;t support it
LOL

Fucking brainlet. Can't even properly encapsulate operations into functions.
>>
>>59391455
>No it deference a pointer to an array of characters.
except I asked you for a fucking pointer, dumb shit
>>59391475
Learn how to use a keyboard, dumb c tard
>>
>>59391457
Needlessly complex and roundabout is what it is
>>
>>59391455
>>that disc usage
>D: 180K
>C: 12K
Are you trying to be sarcastic? Who said anything about disk usage?
>>
>>59391456
>>59391500
In the domain that C works in, these kinds of things are important.
>>
>>59391070
Well why is C popular? I actually don't know
>>
>>59390737
>>59391139
>why doesnt this low level language have 30,000,000 functions already preprogrammed inside 50,000,000 libraries and 3,000,000 frameworks like my Java does :((((((((

You know calling a foreach means diving into a bunch of inheritance bullshit and you just have to hope that it was a well written iterator, yeah?

I'd much rather take

    int i;
size_t n = 0;
if (argc < 2)
return 1;
for (i = 1; i < argc; i++)
n += strlen(argv[i]) + 1;
char *ptr = calloc(1, n);
if (!ptr)
return 1;
for (i = 1; i < argc; i++)
ptr = strcat(ptr, argv[i]);
puts(ptr);
free(ptr);
return 0;

over
>What exactly is happening behind that foreach?
>gee i dunno, something i guess
>>
>>59391490
>moving the goalposts
The original example prints a string, and that would be the use case, but as I stated previously
printf("%p\n", ptr);

if you want the actual pointer itself
I also hope you know that
printf("%s\n", ptr);

and
puts(ptr);

are exactly the same.
>>
>>59391514
In that domain ASM is both
1: Minimal
2: Takes less resources

IDK why C exists
>>
>>59387797
C_Programming_A_Modern_Approach_2nd_Ed.pdf
>>
>>59391537
>What exactly is happening behind that foreach?
If I cared I could have used while loops, is it too hard to understand for a c tard?
>>
>>59391544
People like having portable code, you know.
Assembly is basically the definition of non-portable.
>>
>>59391544
C is portable asm
>>
>>59391544
C is WAY more portable than ASM.
It was literally designed as a portable assembler.

Go ahead and try to maintain a 250,000 lines of code ASM project without killing yourself.
I won't even go to your funeral.
>>
>>59391537
hey anon what exactly goes behind that puts and for?
>>
>>59391123
The problem is to write a function, not a program, dipshit. the point is to write a function that can be used anywhere, with any amount of strings, and returns one single concatenated string.

Not main you fucking dipshit.
>>
>>59391542
puts(ptr) prints a fucking string
printf(all that bullcrap followed by a line break and a placeholder prints a fucking memory address in the stdout, you autistic trash
>>
>>59391579
>puts
The text being copied to the stdio buffers, and eventually being written to a file with the write() syscall.
>for
A while loop, which is implemented as a test and branch in assembly.
>>
File: 2893578235.jpg (726KB, 1932x2456px) Image search: [Google]
2893578235.jpg
726KB, 1932x2456px
101 posts
20 posters
>>
>>59391564
>People like having portable code
I heard c tards like having "minimal" binaries more and thus do not like Java or python
>>59391570
C is bloated and slower asm
>>59391576
see above
>>
>>59391616
>I heard c tards like having "minimal" binaries more and thus do not like Java or python
That has literally nothing to do with what I said.
>>
>>59387797
d-does this references whatever new command introduced by C11? https://www.gnu.org/software/gnu-c-manual/
>>
>>59391602
>for each
first parameter is the current index which iterates over the second parameter (whichi is iteratable) sequentially

boo fucking hoo
>>
>>59391305
The point is to create a function usable in other programs, fuckwit.
>>
>>59391623
portability was not a concern when c tards were crying over disk usage
>>
>>59389366
You are a fucking idiot. From now on keep your mouth shut so that people only suspect that you are a fucking idiot rather than knowing for sure that you are a fucking idiot.
>>
>>59391305
>autist in denial
lmao

puts() cannot print a memory address
>>
>>59391660
Did truth hurt your feelings?
>>
>>59391640
C is much more portable than Java, Python, D, or basically any other meme language you will bring up.
Tell me if those languages work on computers with non-8bit bytes.
>>
>>59389366
>C doesn't come with a language library that has spoiled modern programmers.

I remember having to learn to implement my own libraries before the internet gave you everything.

Shit like this makes me feel old.
>>
>>59389366
(You)
>>
>>59391710
those are not libraries you drooling autist
>>
>>59391123
/* Concatenation */

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

/* Arguments: x: number of strings, any number of string */
char * concat(int x, ...)
{
/* Initialize arguments */
va_list strings;
va_start(strings, x);

/* Calculate size of new string and allocate it. */
int total = 0;
char ** stringList = malloc(x * sizeof(char *));
for (int i = 0; i < x; i++) {
stringList[i] = va_arg(strings, char *);
for (int j = 0; stringList[i][j] != '\0'; j++)
total++;
}
char * z = malloc((total + 1) * sizeof(char));

/* Copy all strings into new string. */
int k = 0;
for (int i = 0; i < x; i++)
for (int j = 0; stringList[i][j] != '\0'; j++, k++)
z[k] = stringList[i][j];
z[k] = '\0';

/* Clean up and return new string */
va_end(strings);
free(stringList);
return z;
}

int main()
{
char * newString = concat(6, "this ", "is ", "a ", "", "concatenated ", "string.\n");
printf(newString);
return 0;
}
>>
>>59391678
>everything should be in my high level bahbee language
>"truth"

You are obviously clueless as to how anything works below the level of your hand holding language. Kernels, drivers, embedded systems, performance critical code, and real time code are NOT going to be written in Java, Python, JavaScript, or whatever else you learned in Pajeet University.

There are certainly places where you would not use C. And there are places where you would not use anything else.
>>
>>59391719
inb4 F R A M E W O R K :^)
>>
>>59391752
>few decades pass by
>0 frameworks accomodate the incompetence that C has
Only because no one uses the language, no wonder C is dying
>>
>>59391750
>high level bahbee language
Those are features. Features and tools that an intelligent programmers use to stay productive instead of wanking all over the language with accidental macro addons
>>
>>59391690
>Tell me if those languages work on computers with non-8bit bytes.
Dawg are you shitting me?

Yeah I don't think that's going to be an issue

There is no limit to how far C-ucks will reach
>>
>>59391630
Not how a foreach works.
>>
>>59391719
>collection of functions, macros, and constants to be used in a variety of programs
>not a library
Are you fucking retarded, 12, or both?
>>
>>59391793
That's exactly how it works in the given snippet
>>
>>59391797
>Contract programming
>Mixins
>Function overloading
>Operator overloading
""library""
Typical angry C toddler with low IQ
>>
File: Screenshot_20170222-125046.jpg (1MB, 1080x1920px) Image search: [Google]
Screenshot_20170222-125046.jpg
1MB, 1080x1920px
21st Century C

(pic unrelated)
>>
File: 1483000558858.png (157KB, 3064x2288px) Image search: [Google]
1483000558858.png
157KB, 3064x2288px
>>59391792
>What is embedded systems programming

>>59391616
>C is bloated and slower asm
As a consequence of not being straight asm, yes, you are correct.
But that same consequence applies and is magnified against languages that aren't C for the same reason it applies to C.

C is great because it's basically one step away from ASM. It maintains the speed and efficiency without requiring you to write 30 lines for a print statement.
>>
>>59391827
That's not what he was talking about dipshit. Most of what he was responding to are easily implemented in C through libraries.
>>
>>59391856
There are some cases where C is actually more verbose than ASM
>>
>>59391810
The way you've written your explanation makes it sound like you're using a for loop, which is way fuckin faster for a task like this because again
No iterable classes
No iterator implementations
No inheritance bullshit
Using a foreach looks clean and is fine, but if you're trying to compare two examples and say "mine is better because its SHORT! HA!" then you've missed the point of ever writing in C.
>>
>>59391881
Good thing C supports inline ASM.
>>
>>59391895
what a shitty language
>>
>>59391662
Yeah you are just fucking retarded. You don't understand pointers at all.
>>59391637
Yeah, no, but if you want that, here:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *concat(int count, char **strings)
{
int i;
size_t n = 0;
char *ptr;

for(i = 1; i < count; i++)
n += strlen(strings[i]) + 1;

ptr = calloc(1, n);
if (!ptr)
return NULL;

for (i = 1; i < count; i++)
ptr = strcat(ptr, strings[i]);

return ptr;

}

int main(int argc, char **argv)
{
char *ptr;

ptr = concat(argc, argv);

if (!ptr)
return 1;

puts(ptr);

free(ptr);

return 0;
}
>>
>>59391881
I can't really think of one, but I don't dispute that claim.
I can write fizzbuzz a lot more succinctly in Perl than in C but I wouldn't want to use that as a basis for any kind of real opinion, other than "look at this whacky thing I can do"

C isn't meant to be used as a super short and fast-to-write language, though it certainly can be. It's meant to be "ASM that's a lot less of a fucking pain to use"
If you told me you were writing a large-scale web backend in C I'd call you a raving fucking lunatic, just like I would if you told me you were writing device drivers or embedded system code in Python
>>
>>59391920
LMAO AUTIST THAT'S A NICE LOOKING MEMORY ADDRES
$ gcc main.c ;and ./a.out abc def 0ca
abcdef0ca
>>
>>59391949
The original solution did not do this.
But again, here:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *concat(int count, char **strings)
{
int i;
size_t n = 0;
char *ptr;

for(i = 1; i < count; i++)
n += strlen(strings[i]) + 1;

ptr = calloc(1, n);
if (!ptr)
return NULL;

for (i = 1; i < count; i++)
ptr = strcat(ptr, strings[i]);

return ptr;

}

int main(int argc, char **argv)
{
char *ptr;

ptr = concat(argc, argv);

if (!ptr)
return 1;

printf("%p\n", ptr);

free(ptr);

return 0;
}
>>
>>59391940
Which is funny because to an average c tard the world of programming is either kernel development or webdev
>>
>>59391994
>The original solution did not do this.
You mean >>59391123
I can see puts(ptr); in the middle of the program
>>
>>59391998
>kernel development
Proper

>webdev
please don't do that
maybe if they're developing like, apache or something
>>
>>59392016
>please do not do webdev
what do you mean? Don't like the internet? How about you turn it off?
>>
>>59392005
The original solution was >>59390737 you idiot.
That one used printf("%s\n", ptr) which is the EXACT same as puts(ptr); The compiler most likely replaced printf() with puts().
>>
>>59391920
>Yeah, no, but if you want that, here:
>reading comprehension
Yeah, it fucking was. The original function was not main, so it could not use argc and argv. You said it looked like shit and then did something completely different. How do I know the point was to make a function to be used in other programs? Because the original code that was posted was something someone wrote in response to a function I wrote to do that in /dpt/. Now go fuck yourself you stupid piece of shit. Also your code is horseshit. You start i at 1, which is wrong because this function can no longer be used anywhere
>>
>>59392037
Please do not do webdev in c
Preferably don't do it at all so we stop getting retards developing 18 new frameworks every other week

We need more stodgy old dudes running the show to just yell "NOPE" loudly whenever somebody suggests using nosql or javascript for something
>>
>>59392042
>The compiler most likely replaced printf() with puts().
puts cannot print memory address

Also, not you but
using -o3
Aww the edge
>>
>>59389366
>Average person hating on C writes entire paragraphs against it

>Average C programmer is busy not being on /g/

Says a lot
>>
>>59389918
>C is an awkward uselessness in the middle
>Use c++
I fucking lol'd
>>
>>59391791
Again, you are obviously clueless.

Go ahead and try to write a kernel in your high level language. Come back and let us know how it goes.
>>
>>59389155
Why? You don't know C, how can you be picky about the book you want to learn form?
>>
File: tard.jpg (72KB, 1024x512px) Image search: [Google]
tard.jpg
72KB, 1024x512px
>>59389366
>t. Millenial fag.
Literally all these feature can be done on c.
>>
>>59389366
>doesn't realize all of these shitty "features" in his baby language are literally implemented in C
lol
>>
File: 1488406193199.jpg (30KB, 400x565px) Image search: [Google]
1488406193199.jpg
30KB, 400x565px
>tfw the autists hating on languages only make me want to use them more
>>
>>59392348
Give me an example of meta programming in C you dumb fucking gay tripshit

>>59392374
>Implemented in C
No and C doesn't have 'em
>>
>>59392380
I get this too. It creates a whole "us vs them" attitude, and just makes me want to use it even more, just to spite them.
>>
File: 1489461328707.png (740KB, 1834x1200px) Image search: [Google]
1489461328707.png
740KB, 1834x1200px
>>59389366
C(ucks) BTFO
>>
>>59391549

this book is nice.
>>
>>59389366
List functional Kernels or OS built with high level programming languages, brainlet hipster
>>
>>59392387
>C is just shitty portable assembler
>you can't do X in C

If your high level language runs on a CPU...any CPU...then I'm pretty sure its features can be implemented in C.

In fact, they probably were which is how your high language was born you fucking idiot.
>>
Back to the subject of the OP. I am currently working through the K&R book. It's ok so far. I appreciate how concise the explanations are, but sometimes I feel like they don't cover certain concepts with enough depth and I end up using google to get a better understanding. Anyone else feel this way?
>>
>>59387797
To stay on topic, I recommend this book if you're a beginner:
https://www.amazon.com/C-Programming-Modern-Approach-2nd/dp/0393979504/

Crystal clear and actually reads like a book.
>>
since there's no /sqt/ thread I'll ask here: I want to learn how computers work from scratch. Is there a good book or books for a noob that covers everything starting with transistors?
>>
>>59390737
Holy fuck this example is shit. I can write a better C code than this.
>>
>>59393906
Impossible to cover it all with a single book but "Computer engineering" should be the keyword you're looking for, then various processors' developer manual.
>>
>>59389995
I like C but you sound like you don't know the first thing about programming tbqhfam
>>
>>59395186
I just realized he compared a function in C to a main function in D.

What makes it trickier is that for it to be a function you can't use argc and argv.
>>
>>59395429
How so?
>>
>>59395621
you're overly excited and sound like you just started muh computer science 6 months ago
>>
>>59395676
Do you have specific examples of what I was saying that was wrong, factually or otherwise?
>>
>>59389366
Oh blown the fuck out. I can only imagine how angry C fags will get at this
>>
>>59390705
Then stay in reddit you piece of subhuman garbage
>>
The C machine and memory models are abstractions for how many real hardware platforms work. It's low level enough to use hardware features without too much fuss and it's portable enough so that your C skills aren't useless on different platforms.
Free C toolchains exist for many popular platforms. It's a language small enough to be reviewed and used within one college semester and has a stable standard definition. A lot of other languages which have features desirable to developers also have shortcomings compared to C in certain applications.
Thread posts: 174
Thread images: 10


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.