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

Name one (1) flaw.

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: 325
Thread images: 31

File: C-Programming.jpg (22KB, 593x173px) Image search: [Google]
C-Programming.jpg
22KB, 593x173px
Name one (1) flaw.
>>
The developer
>>
Is not c++
>>
Can't dinamically execute statements.
>>
#include <stdio.h>

void f1() {
int a=1, b=2, c=3;
}

void f2() {
int a, b, c;
printf ("%d, %d, %d\n", a, b, c);
}

int main()
{
f1();
f2();
}


Stack leaking
>>
>>59720171
(void *)
>>
File: kasparov-mic.jpg (15KB, 182x238px) Image search: [Google]
kasparov-mic.jpg
15KB, 182x238px
>>59720226
That's a good thing
>>
>>59720171
memory management
>>
>>59720171
Flaw 1:
It's not C++
Flaw 2:
It's not C#
Flaw 3:
It's not Python
>>
>>59720171
>3rd grade in school notes system
>not A
>>
Can't compete with handcoded assembly in many cases, unless you run it through a superoptimizer.
>>
>>59720171
null terminated strings
buffer overflows
segmentation faults

>b-but those are the programmer's fault
if a car is only safe to drive when the driver is an ace, there's something wrong.

naturally, the analogy isn't perfect, but still, C is ill suited for most tasks nowadays.
>>
>>59720278
That's a feature.

>>59720320
That's why inline asm exists.
>>
File: 1461613889307.jpg (56KB, 945x482px) Image search: [Google]
1461613889307.jpg
56KB, 945x482px
>>59720171

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 software industry. If you want guaranteed memory exploits and security vulnerabilities in your program with timesink development period then use Assembly, not C.
>>
>>59720288
>Flaw 2:
>It's not Poosoft Spybot shit
>Flaw 3:
>It's not interpreted shit
>>
File: c.jpg (69KB, 900x471px) Image search: [Google]
c.jpg
69KB, 900x471px
>>59720328
>>
File: 30303318.jpg (21KB, 400x400px) Image search: [Google]
30303318.jpg
21KB, 400x400px
>>59720382
>>
>>59720425
I have a hard time believing C++ is inherently spied on.

I can see an IDE being spied on. As a matter of fact, Notepad++ was confirmed to have a CIA backdoor by Wikileaks, but was fixed in a patch after the leak.
>>
>>59720171
lacking standard library.
it doesn't even have simple data structures like hash tables, trees or queues.
>>
File: I-can-count-to-potato.jpg (77KB, 407x405px) Image search: [Google]
I-can-count-to-potato.jpg
77KB, 407x405px
>>59720328
>the world should be built for the lowest common denominator
>intelligent people just have to suffer for the safety of all
I hate mommy coder camp graduates.
>>
File: 1489465717612.jpg (31KB, 601x508px) Image search: [Google]
1489465717612.jpg
31KB, 601x508px
>>59720441
No amount of squirming will make the list of flaws untrue, anon.
>>
>>59720454
???

I didn't even reference "Flaw 1: It's not C++"
>>
>>59720479
>claims language is for overgrown toddlers who can't learn advanced things
>BITCHES THAT THE LANGUAGE DOESN'T INCLUDE "ADVANCED THINGS" PREBUILT BY OTHER PEOPLE
I bet you can't even FizzBuzz.
>>
>>59720484
You were talking about poosoft spybot shit in reference to C, right?

What makes you specifically say spybot?
>>
>>59720171
>Name one (1) flaw.

Functions like strcpy(), strcat(), etc. are unnecessarily unsafe. It would not have taken much to make them safer, yet still keep them simple.
>>
File: ace.jpg (23KB, 283x309px) Image search: [Google]
ace.jpg
23KB, 283x309px
>>59720382
>C is from stone age and the people who still preach it is like overgrown toddlers that can't learn advanced things.
It's still better and more efficient than any modern language(s)
>C doesn't have delegates
Useless high level concept
>C doesn't have resizable arrays
Realloc, do you speak it
>C doesn't have strings
Implement your own
>C doesn't have string concatenation
Implement your own
>C doesn't have namespaces
Useless high level concept
>C doesn't have exception handling
Useless high level concept
>C doesn't have closures in the standard
Useless high level concept
>C doesn't have unit tests
False, there's several frameworks in existence
>C doesn't have Function overloading
Use variadic functions
>C doesn't have memory safety of any kind
You're supposed to be a real programmer to use C
>C doesn't prevent memory exploits and has no bounds and runtime checks
You're supposed to be a real programmer to use C
>C doesn't have dynamic method loading/creatin
Useless high level concept
>C doesn't even have generics and templates
Useless high level concept
>C doesn't have meta programming
It has a preprocessor so by extension it has metaprogramming
>C doesn't have mixins
Useless high level concept
>C doesn't have higher order functions
Useless high level concept
>C doesn't have contract programming
Useless high level concept
>C doesn't have inner classes
Useless high level concept
>C doesn't have function literals
Useless high level concept
>C doesn't have array slicing
Implement your own
>C has a very limited support for implicit parallelism
Useless high level concept
>C doesn't even have string switches
Useless high level concept
>>
>>59720543
>High level is useless
Babby's First Programming Ethic
>>
>>59720590
>my college textbook said it's good so it must be
>>
>>59720590
High level is not useless, but those concepts are useless in C. Simplicity is a hell of a drug.
>>
File: 1490016143652.jpg (33KB, 567x565px) Image search: [Google]
1490016143652.jpg
33KB, 567x565px
>>59720622
I didn't say that
>>
>>59720382
This graph looks fucky. They must have mixed C and Objective C. "C" in the graph starts dropping right when Swift is out. That source looks like shit. And I don't think C was ever that popular recently anyway. C is niche language for high performance, you can't add high level concepts without sacrificing performance.
>>
File: aceventura.jpg (7KB, 216x243px) Image search: [Google]
aceventura.jpg
7KB, 216x243px
>>59720766
https://www.tiobe.com/tiobe-index/
>>
>>59720468
you don't have to like it but you have to deal with it. get over yourself and accept that type safety and other such abstractions aren't just meant to protect against incompetent programmers, but also to make programmers in general more productive. time not spent scrutinizing your code base for C's many pitfalls can be spent churning out more shit.

in the end, your tools should reflect your actual needs, not some clueless basement dweller's notion of what proper programming practice is.
>>
>>59720526
>Poosoft
>"What makes you specifically say spybot?"
The abstract syntax of C# might be botnet free. I wouldn't trust any aspect of its implementation to be.
>>
>>59720516
w-why aren't you reinventing the wheel... I reinvent the wheel every day... why should you have it easier... it's not fair...
>>
>>59720235
I don't get it anon... won't it just print null 3 times?
>>
>>59720465
>lacking standard library
Sorry, but THE Standard library is part of the C standard.
>>
>>59720235
>does something stupid and get a stupid result
>C SUCKS GUYS
>>
>>59720915
.net core is MIT licensed, and this includes the CLR as well.

I would not defend MS without a good reason but the fact of the matter is that the latest C#/.net tech is literally free as in freedom and available for you to peruse.

this is something we should commend lest people start thinking we're a bunch of partisan shitheads.
>>
>>59721024
there's nothing wrong with C

there's something wrong with using C for shit that other tools would be better at because you're a thick headed nerd cunt
>>
>>59720903
>get over yourself and accept that type safety and other such abstractions aren't just meant to protect against incompetent programmers, but also to make programmers in general more productive.

I'll grant that some high level language features improve productivity in many (not all) situations. But productivity has become a fucking meme pushed by people who love the sound of it, but not the part where you actually prove it with measurements.

Case in point: Java is a "high level" language with "safety and abstractions" which might make it productive if it wasn't for the 50 billion class Enterprise frameworks that make any Java project spaghetti code.

Case #2: I've done coding competitions in Python and C and I'm not convinced that Python is all that productive. Sometimes it is, but just as often it's not because you have to spend time tweaking for speed where the C version was lightening fast out of the gate.

>time not spent scrutinizing your code base for C's many pitfalls can be spent churning out more shit.

"Churning out more shit" is the appropriate terminology since so much software today is in fact shit.

>in the end, your tools should reflect your actual needs, not some clueless basement dweller's notion of what proper programming practice is.

I would agree with this. However, my "needs" do not include hiring Pajeets at a lower rate than real engineers.
>>
>>59721024
>re-using variable names in completely different scopes
>"stupid"

good thing most C devs don't name all their iterators "i" or something
>>
>>59721091
>t. pajeet programmer
Using uninitialized variables is the stupid part
>>
>>59720902
I know it's www.tiobe.com. I can fucking read. But do you? Did you read this?:
>They must have mixed C and Objective C. "C" in the graph starts dropping right when Swift is out.
There is now Objective C in this graph. Apple is switching Objective C with Swift, that's why the """C""" in this graph is dropping. This graph is built by an autist.
>>
Despite its potential flaws, is C a good choice for first programming language to learn?
>>
>>59720171
>>59720186
Is not Python
>>
>>59721121
because blindly pointing towards addresses is inherently better than simple zero-values

I get it, your half-century old technology can do no wrong whatsoever
>>
>>59720235
Why is this a problem?
>>
>>59721162
it actually is. afterwards you'll want to move on to something more modern though.
>>
>>59721174
Except in the end, that's how the underlying architecture works. Everything else is an abstraction that will inherently be slower.
>>
>>59720382
Thanks for enumerating all the useless bloat C doesn't have.
>>
File: spakker.jpg (37KB, 970x646px) Image search: [Google]
spakker.jpg
37KB, 970x646px
>>59720235
this is the most spakker shit ive ever seen
>>
>>59721229
>I don't know how to use a feature
>Must be bloat
>>
>>59721194
the cost of such an abstraction is negligible, and in most cases, even Java (which I'm not defending) is fast enough.

I don't deny that C still has many uses in this day and age, but C purists really need to commit suicide promptly
>>
malloc
Ada is superior in almost every way

>>59720243
great for abstracting handles to stuff t. rtos dev
>>
>>59721125
My point wasn't to argue against you, it was to confirm your point. See how high C is on that list.
>>
>>59720171
default libs are ancient and miss most common use cases. Take a programming challenge I had for a job interview. Take an array and order it and remove all duplicate entries. literally a one liner in Python. Took me the better part of three hours to program a working implementation in C.

I still love C though
>>
>>59721162
Yes because it will teach you to be strict as fuck about your code. Other languages will seem like toys after that.
>>
File: I-can-count-to-potato.jpg (35KB, 600x597px) Image search: [Google]
I-can-count-to-potato.jpg
35KB, 600x597px
>all these C doesn't have x comments

you don't understand neither C nor unix philosophy. read Dennis Ritchie.

>A language that doesn’t have everything is actually easier to program in than some that do.

C has flaws though, most of them became obvious as the language got older, it's 45 yo now and it's still relevant.

I programmed in C most of my programming life and the most important real life problems with C is the way strings handled and the lack of garbage collection.

I switched Go and i am more than happy now, it was a very smooth transition and many thing made sense immediately, almost like i already knew Go in another life.

The problem with this kind of threads is that people who use C for only homework assignment and never code something serious have strong opinions about it either in good or bad way.
>>
>>59720382
oh look dis again
>>
File: hide.jpg (753KB, 1500x1000px) Image search: [Google]
hide.jpg
753KB, 1500x1000px
>>59721285
there is no need for it to exist
>>
File: 31siliconvalleyweb-tmagArticle.jpg (73KB, 592x395px) Image search: [Google]
31siliconvalleyweb-tmagArticle.jpg
73KB, 592x395px
>>59721327
>took me 3 hours for a trivial task
>>
>>59720382
Csharp is cancer
Microsoft is cancer
>>
>>59721420
C# is surprisingly decent, apart from all the syntaxical sugar they keep shoving into the spec lately

and I say this as a huge GNU nerd who has to use it to put food on the table

the shit people make with it would give you nightmares though
>>
>>59720235
no shit retard
>>
>>59721437
Microsoft cant keep a reference page for shit though. Have you eber tried to look through microsofts library documentation. Shits a headache
>>
>>59721258
If i actually didn't know how to use a feature would de because i never needed to know, and if i never needed it, it would be by defenition BLOAT.
So i dont get your point.
And I actually had to learn all that useless shit in my CS course.
>>
>>59721370
>trivial means it should take no time at all
I'm sorry you're autistic
>>
fflush
>>
>>59721370
>O(n) or greater
>trivial
Kys faggo
>>
>>59720235

Undefined behaviour. What's yer point, fag?
>>
>>59721474
There are lots of things you don't "need" to do if you are doing things the hard way.

Beware the Turing tar pit, where anything is possible, but nothing interesting is easy.
>>
>>59721565
There is no generic sorting algorithm better than O(nlogn) though
>>
>>59721285
The cost of such abstraction is negligeble in most cases, not all.
And btw why is zero better for initialization than any other value?
>>
>>59721625
Im talking best case here. Not average case.
Hence the "or greater"
>>
>>59721632
The cost for abstraction like that is felt at compile tieme,
>>
>>59720171
Shit tier library, even for what it does. In particular for what it does.
Bonuses:
1. header files
2. lack of decent metaprogramming
>>
>>59721651
So.. bubble sort?
>>
>>59721632
>negligeble
by whose standards?
The problem with abstraction is that once you start doing it, there is no clear indication where to stop. So you can quickly get abomination shit like javascript at your hand
>>
>>59721585
Most stuff becomes the easy way with the right library and you dont need to do the most eficient code from the start. In C you can always go back and optimize the functions you need.
>>
>>59721666
Are you retarded? Initialization of a variable with a specific value requires it to be written to memory.
>>
>>59721744
>So you can quickly get abomination shit like javascript at your hand
The problem with JavaScript isn't abstraction.
It's called being vague (dynamic anything), automation (garbage collection) and running in a shit tier environment using a shit tier execution model.
>>
>>59720171
pointers
>>
>>59720537
So just use strncpy instead?
>>
>>59721703
>doing bubble sort for a 10 minute interview question
Good luck even scratching that shit down on paper in that time.

>>59721370
Here's me redoing it in the time since I posted my other reply (>>59721494)

#include <stdio.h>
#include <limits.h>

int * foo (int * N, int size)
{
int I[size];
int * T = malloc(size * sizeof(int));
int temp;
for (int i = 0; i < size; i++) I[i] = N[i];
for (int i = 0; i < size; i++)
{
T[i] = INT_MAX;
for (int j = 0; j < size; j++) if (I[j] <= T[i])
{
T[i] = I[j];
temp = j;
}
I[temp] = INT_MAX;
}
temp = size;
for (int i = 1; i < size; i++) if (T[i] == T[i-1]) temp--;
int * M = malloc(temp * sizeof(int));
int j = 0;
for (int i = 0; i < size; i++) if (T[i] != T[i-1]) M[j++] = T[i];
return M;
}

int main (void)
{
int N[10] = {10, 1, 4, 6, 2, 1, 3, 4, 7, 9};
int * M = foo(N, 10);
printf("N: ");
for (int i = 0; i < 10; i++) printf("%d, ", N[i]);
printf("\n");
printf("M: ");
for (int i = 0; i < sizeof(M); i++) printf("%d, ", M[i]);
printf("\n");
}
>>
>>59721845
>>59721370
for reference, here's my solution in python.

def foo (N):
return sorted(set(N))


def main():
N = [10, 1, 4, 6, 2, 1, 3, 4, 7, 9]
print (str(N))
print (str(foo(N)))

main()
>>
>>59720171
Its handling of strings is lackluster.
And yeah, I know that someone is now about to say "but it's a low level systems language" or something to that effect, but that doesn't excuse it. It still has to parse and read text files to check its configuration. It still has to do logging. It still has to do a lot of string stuff even if it's a low level language.
>>
>>59721802
>one of the most powerful features of C
>flaw
>>
>>59721935
And a lot of other things. In fact, from the things missing, complete string handling is the least concern.
>>
>>59721845
>brackets on a separate line
i puked
>>
>>59722012
>The position of braces is less important, although people hold passionate beliefs. We have chosen one of several popular styles. Pick a style that suits you, then use it consistently.
It's okay to be a fucking child, but you should do it elsewhere
>>
>>59721845

That's the most retarded style I've ever seen. You should fail the interview for having no taste.
>>
>>59722071
see >>59722059
>>
>>59720382
>C programmers are actually retards in general
I think it's just the majority of programmers who are retards.

It's easy to find someone who can program in C, but it's hard to find someone who can do it well.
>>
>>59721845
>for (int j = 0; j < size; j++) if (I[j] <= T[i])
>{ }
Wtf are you doing, this is the first time ever I see this. Add extra brackets for clarity and don't nest statements like this. It's ugly as hell and obscures the purpose of what you're doing.
>>
>>59721953
>segfault
>feature
>>
>>59722289
>i can't program
>flaw
>>
>>59721174
>every memory location in every language ever is initialized for you
>t. Sanjay
>Mumbai University

>>59721285
>the cost of such an abstraction is negligible
Except that it's not. We have billion instruction per second processors and solid state mass storage and there's STILL plenty of software which lags and makes the user wait.

>>59721437
>the shit people make with it would give you nightmares though
This is my problem with the whole God damn industry. Software engineering is supposed to be ENGINEERING. Not Pajeet or Mommy Coder.

>>59721845
>>59721918
>uses library sorting function in Python
>tries doing everything manually in C
>HURR DURR C IS SO DIFFICULT IT TOOK ME THREE FUCKING HOURS!
http://www.cplusplus.com/reference/cstdlib/qsort/
>>
>>59720235

Printing ubinitlaized pointers contents and hoping they don't cross with initialized. Wow you're retarded.

T. Java fag
>>
>>59722012
>>59722071
>>59722115
This is an interesting development.

I mash this trash code out in 15 minutes, and instead of legitimate criticism (such as my choice of variable naming, my extra for loops that can have their internal logic moved, my reuse of variables, my calling printf() twice in a row), /g/ decides to have an autist spasm about my choice to use the Allman indentation style

>>59722342
the question was to make a function. qsort requires that I write a second function to compare.
>>
>>59722395
Nevertheless it's unsafe behavior and C is too dangerous we all need to use Java.
>>
>>59722402
Giving your shitty style a big name doesn't make it any less shitty. It's hard to read, and you should reconsider it.
>>
>>59722482
No. Please stop complaining about my indentation style. I'm not going to change it to appease your autism.
>>
>>59722547
YOU'RE FIRED
>>
>>59720235
I like this post that C has started this post.

Use Java instead it is safer and more demonstrative
>>
>>59720382
REEEE
>>59720543
THIS
>>
>>59720171
no RAII
>>
>>59720382

(((tiobe)))
>>
>>59722342
>every memory location in every language ever is initialized for you
if I explicitly asked for it then why the fuck not

>We have billion instruction per second processors and solid state mass storage and there's STILL plenty of software which lags and makes the user wait.
and memory safety is somehow responsible for this? that's a huge leap you're making.

with "billion instruction per second processors" we can afford a little bit of peace of mind.

>>59722342
>This is my problem with the whole God damn industry. Software engineering is supposed to be ENGINEERING. Not Pajeet or Mommy Coder.
which is exactly my point. imagine if those people were using C.

as I said earlier, you don't have to like it. you have to deal with it.
>>
>>59720948
Depending on the compiler it'll usually print "1, 2, 3\n", because f2() never initialized its variables, and so when called, they are whatever was left over, in this case, the three variables that were initialized, but never operated on. It's a wanton abuse of undefined behavior to make a nonissue look like some sort of security flaw.
>>
>>59722472
>unsafe
Unsafe how?
>>
>>59721091
>he thinks the variable names are the cause of the issue
Wow you're literally retarded
>>
>>59721091
ur dumb son
>>
>>59720382
/thread
>>
>>59720543
>That level of damage control
Now that's just sad
>>
>>59723376
Go back to your training wheels programming language. The adults have memory that needs direct addressing
>>
>>59720235
Dumbfucks who don't put all opening braces on a separate line.

#include <stdio.h>

void f1()
{
int a=1, b=2, c=3;
}

void f2()
{
int a, b, c;
printf ("%d, %d, %d\n", a, b, c);
}

int main()
{
f1();
f2();
}

Fixed it for you, moron.
>>
>>59720235
I compiled this online on two sites and got "0, 0, 0" on one site and "1, 2, 3" on another.
>>
>>59723540
>different compilers will handle undefined behavior differently
Rely mak u dink
>>
>>59722289
>>59723505
you couldn't even do [ code ] , only subhumans do opening braces on a new line
>>
>>59723567
So wouldn't that be the fault of the compiler, not the language?
>>
>>59720226
Yes it can
>>
>>59723571
t. Javbabby
>>
>>59720226
Take a look at mmap
>>
>>59720171
Steep learning curve compared to other languages.
>>
>>59723619
making some wild assumptions there
>>
>>59723505
>wasting a whole line on a single character
>>
>>59720382
C has a very limited niche. However ASM is far better than C in those niche
>>
File: 1484229116610.jpg (49KB, 600x381px) Image search: [Google]
1484229116610.jpg
49KB, 600x381px
>>59723413
>training wheels programming language
That's C. Toddler toy rhyme book on the left, and a book for grownups on the right
>>
>>59723594
Yes, it's undefined behavior (platform specific behavior. No standard on what the value should be).
>>
>>59720543
>Namespaces are useless
Spotted the unhireable fat basement dweller
>>
>>59720226
>dinamically
>>>/india/
>>
>>59723978
Namespaces ARE useless though.
What do they achieve, besides fucking with what could have been a simple ABI?

>>59723975
>platform specific behavior
This is a terrible way to describe what undefined behaviour entails.
Compilers have absolutely no obligations when it comes to undefined behaviour. You could write a compiler that that emits code to delete all of your files when it detects undefined behaviour, and it would still be a conforming compiler in terms of the C standard.
Don't confuse undefined behaviour with implementation defined behaviour.

>>59723907
>C is for writing efficient, yet portable programs
>ASM is far better at that
Assembly is basically the definition of unportable.
>>
>>59721286
What's wrong with malloc? malloc is comfy as fuck.

MAXIMUMLY
ALLOCATED
LUXURIOUS
LOFT
OF
COMFY
>>
>>59724091
Portability is for programmers that cannot program. I guess far a C toddler it's justified to think otherwise
>>
>>59720328
>null terminated strings
What is wrong with these?
>>
>>59724123
Pajeets are too stupid to use them properly.
>>
>>59724123
slow as fuck to get the size
>>
>>59720382
Most of those things that you mentioned would really make sense to include in a language like C. Most importantly, memory is manually managed, so where are these closures or concatenated strings going to be put? There is no concept of "class" in C which means that mixins, inner classes, generic, and all the other OOP stuff don't make sense to add, either. Almost everything else that you mentioned can be implemented in C, with the exception of namespaces and function overloading (but these are really just fancy mechanisms for name mangling).
>>
>>59721327
>Took me the better part of three hours to program a working implementation in C
Sounds like you're just retarded.
>>
>>59724151
You can actually do function overloading in C, using C11 _Generic.
It's how <tgmath.h> could be implemented.
>>
>>59724175
ewwwwwwww
>>
>>59723505
That's cool for sub-50 lines programs but once you pass this point and start calling shit inside shit inside shit it gets messy pretty quick.

It makes me wanna commit sudoku when someone shows me a code like that.
>>
File: Hermann_Emil_Fischer_c1895.jpg (120KB, 400x566px) Image search: [Google]
Hermann_Emil_Fischer_c1895.jpg
120KB, 400x566px
>>59724151
>would really
wouldn't* really
>>
>>59721845
>Good luck even scratching that shit down on paper in that time.
Bubble sort with an optimation to stop when the list is sorted should take like 10 lines of C and five minutes tops.

>code
Yep, you're retarded.
>>
>get invited to C programmer's house
>every door leads to a black void that may or may not point to an actual room
>only some of his doors even have locks or handles
>they all work differently
>you have to carefully check if the handle is properly attached to the locking mechanism
>or if the hinges are even in place
>if you forget, the whole thing collapses when you open it
>none of his windows contain any glass
>they didn't come with that from the hardware store
>he hasn't gotten around to implementing glass yet
>ask to use his toilet
>he has two of them
>one to pee, one to poo
>use the poo one
>fucking thing overflows
>it's only designed to handle 16 bits of shit per flush
>>
>>59720171
1. Basic types that change size depending on your platform.
2. Arrays that decay to pointers.
3. Null-terminated strings.
4. All standard library string functions that are ignorant of string length that still haven't been removed yet.
5. scanf's format specifiers that don't specify a width.

These are undeniable deficiencies of the language. It is possible to program your way around most of these deficiencies, but these features shouldn't have been a part of the language in the first place.
>>
>>59723567
Not not really
>>
>>59724898
>3. Null-terminated strings.
But this is easiest way of doing it, and probably most efficient.
>>
>>59721162

That's what I'm doing now, decided to start the Euler problems in C.

To be honest, having to manually write functions that generates primes from 1 to x is kinda fucking with me, but it is kinda intersting to actually think about the best way to implement them is.

When I get to matrix multiplication and shit I'll probably want to kill myself, however.
>>
>>59725050
>current year
>not using '$' terminated strings
>>
>>59723940
>C
>training wheels
IMAX level projection going on here

>>59724173
Go try to program in a language you haven't touched in years and see how long it takes to do something really simple.

>>59724244
Sorry I confused bubble sort and heapsort.

>>59724961
>not not really
>not not
So then really really?
>>
>>59725050
Maybe, but there was no excuse for pairing shitty null-terminated strings with even shittier standard library functions that don't give a shit about the size of the underlying buffer.
>>
>>59720171
Behold, the world's most egregious misunderstanding of "elegance":

/* canonical K&R string copy */
void strcpy(char *s, char *t) {
while ((*s++ = *t++));
}


Fragile C strings, array decay, and erratic operator precedence and pre/post-fixness all go hand in hand.
>>
>>59722402
>/g/ decides to have an autist spasm about my choice to use the Allman indentation style
That's mostly because you're one of the very, very few people here who actually program. 99% of this board is little kids using Thinkpads and GNU/Linux as costume props for their sad attempts at hacker LARPing.
>>
>>59725050
>>3. Null-terminated strings.
>But this is easiest way of doing it, and probably most efficient.

It's fractionally more space efficient, which is great I guess if you're on a PDP-11 with 256kB RAM, but that's it.

Copies/concatenations can be done substantially faster with explicit length fields due to loop unrolling etc.
>>
>>59724579
Very good. However, the question necessarily arises: do you really need a house?
>>
>>59722402
>the question was to make a function. qsort requires that I write a second function to compare.
I would have rejected your application for failing to use qsort and write that (trivial) 2nd function.
>>
>>59722690
>>>59722342
>>every memory location in every language ever is initialized for you
>if I explicitly asked for it then why the fuck not
You didn't explicitly ask for it. If you had there wouldn't have been a problem. Explicitly asking for it:
calloc
memset
int i = 0;

>>We have billion instruction per second processors and solid state mass storage and there's STILL plenty of software which lags and makes the user wait.
>and memory safety is somehow responsible for this? that's a huge leap you're making.
What you call "memory safety" is part of it.

>with "billion instruction per second processors" we can afford a little bit of peace of mind.
In some places we literally can't. In other places a "little" peace of mind would be fine, but making end users wait because you're a lousy programmer is not "little."

>>>59722342
>>This is my problem with the whole God damn industry. Software engineering is supposed to be ENGINEERING. Not Pajeet or Mommy Coder.
>which is exactly my point. imagine if those people were using C.
Imagine having to be competent in C (which is really the same as saying competent in the lower level details of computer architecture) to program at all.

You're defending a world where idiots can call themselves architects because we only have pre drawn blueprints for box buildings. And your defense is if every architect created his own blueprints buildings would fall down. How about we have competent architects instead?

>as I said earlier, you don't have to like it. you have to deal with it.
And you have to deal with the fact that C is going to be around for a long, long time because all your fancy abstractions rest on a foundation that has to be written in C or assembler.
>>
>>59724579
So you really don't understand that the things you hate in C are in fact how the silicon works?

C is portable assembler. The CPU has no idea if a pointer leads to a black void or valid data. That you believe otherwise because babby's first language gives you high level memory management is cute, but that language only exists because guys smart enough to understand the CPU and C wrote an abstraction for you.

But someone...sometime...has to understand it's an abstraction and be able to code below it.
>>
Inferior to pascal in every way
>>
>>59721326

Oh.

Right.

I "C," heh heh.
>>
>>59726954
>I would have
You'd have to be in a position of authority to do that though
>>
>>59725473
This is what infuriates me about K&R. Being too clever by half. They even encourage this sort of bug-prone minimalism throughout the text.

It's a seminal work, but if anybody ever tells you that it's a decent book to actually learn the language from, it's safe to assume that they either don't know what they're talking about and just repeating a meme, or they actively want you to be a determent to the software industry at large.
>>
>>59720382

> no advanced features like C++

Now if only those "advanced" C++ features made life easier like they do in a real language.
>>
>>59720171
It's not Lisp.
>>
>>59720235
Actually, the program is under no obligation to allocate any stack at all once main() is entered. f1() only assigns to variables, an operation with no side-effects, and does not read from them before reclaiming them through stack frame destruction, so the entire call may be safely eliminated under the as-if rule. f2() reads from uninitialized storage, something which is undefined behavior that the compiler can assume will never happen, meaning it can safely remove the entire function call since the function can never be called in a conforming program.
>>
>>59720382
LOL, you know you can implement your own namespaces as well same with macro templates, if you really wanted to any high level concept can be implemented INSIDE C it just takes smart programmers to code it not shitteir ones who need muh high level to code.

ASM, C, and Holy C are the only real langauges all the others are bullshit that should be killed
>>
File: digustedorangry.jpg (32KB, 354x265px) Image search: [Google]
digustedorangry.jpg
32KB, 354x265px
>>59723142
why doesn't C just intialize it for you?
I don't see any reason why it shouldn't. is there an actual use case for this?
>>
>>59721285
>even Java is fast enough
t. has never used game AI written in Java
>>
>>59721935
Storing data in text files is probably the best way for a systems language to keep long-term state. And at least C usually autoflushes its I/O streams, unlike Rust. But I'm sure the RIDF is going to tell me that's just a way of playing 4D chess to make sure people learn the importance of flushing I/O.
>>
>>59720171
int var1 = 1;
~CODE lines~
var1 = 2;

Result: After var1=2; line, it also decides to clear out a file I had previously opened / closed inside the extra CODE lines. This happened today. I have no idea wtf I did wrong.
>>
>>59723907
ASM is far harder to write code in. I mean, C is fairly low level, but it doesn't make you worry about saving registers and cleaning the stack.
>>
>>59724119
Wrong. A programmer should always endeavor to do the least amount of programming possible. If you think programming is about writing code, you're no programmer.
>>
>>59724133
Yeah and DOS fixed that back in the eighties.
>>
>>59728295
>Thinking macros are a viable way to shore up the deficiencies of C, ever.
Spoken like somebody who has never had to unravel macro abuse.

Multiple nested macros upon macros upon macros that are impossible to sift through and make sense of, so you simply just compile your program with -E and sift through megabytes of output to finally figure out what's going on, only to realize that the macros are hiding abuse so unspeakable - like, say, defining global variables in a specific sequence to lay out data in a custom data segment - that you question why you've been put upon this earth in the first place.

I'll take templates, thanks.
>>
>>59728421
There are approaches to problems that would take minutes if you did it in the shortest number of lines whereas some extra coding could get the same approach done in seconds. Generally speaking less lines = faster execution, but not always!
>>
>>59725118
That doesn't have any advantage over null-terminated strings, except maybe to vastly increase the probability that you'd find out right away that you left out a terminator.
>>
>>59727515
Does Pascal even have pointers or proper arrays?
>>
>>59724091
asm is portable if you use a pseudo assembly like gas syntax or nasm syntax
>>
>>59728539
How is that "pseudo assembly"? They do use "pseudo instructions" (macros), but most of the code is actual instructions. It might be possible to port NASM code between 16/32/64 bit x86 processors, but it would take a lot more work to get it running on a 6502 or ARM.
>>
>>59728421
it would be simpler to do bubble sort for everything why do we have quick sort? i thought programmers wanted to do everything with as little code as possible so they should only use bubble sort
>>
>>59728560
yes however that is a different story it is not completely unportable if it is portable between certain things, now nasm is portable between arm and intel provided you use risc style programming in it
>>
>>59720171
I have a feeling that demand for it is going to dwindle very fast soon.
>>
>>59728562
No, because you need to think through multiple levels of indirection. If you have no libraries to provide sorting algorithms, and have to do some sorting in some hobby project, you might as well use bubble sort since performance isn't an issue. But sooner or later, someone IS going to need to use quicksort, because there ARE cases where performance is important. And in those cases, it's better to write the algorithm once, and then share it with others, rather than reimplement it every time yourself. C uses quicksort as a standard sorting function because it's efficient and including it as library code doesn't really place any extra burden on the programmer. But if everyone had to write their own sorting algorithms from scratch, quicksort wouldn't be the most popular or optimal in all cases.
>>
>>59724104
>Declares a string on the heap
>Uses malloc to resize as necessary during execution
>Segfaults on some instances
>WTF?
>Resorts to using a string of a large size on the stack :(

Where did I go wrong?
>>
>>59728452
this is why you should not use them and what purpose do you really have even using templates? i have done computer vision for a while now and never once have i had to use templates same with my ai stuff
>>
>>59728593
And most people probably aren't going to be using risc style programming if they're mainly targeting x86. Granted, you can write non-portable code in C as well, but the "culture" of planning your code to be portable seems to be much stronger in C than in asm.
>>
>>59728618
I think if you're resizing an existing dynamic array you should use realloc, not malloc.

>>59728622
Templates are mainly for library implementors who want to create data structures that handle a wide variety of data. For example, you might write a generic stack data structure, and in an OOP language you want it to be able to customized to hold any potential user-defined class.
>>
>>59728607
now you are contradicting yourself

>a programmer must write little code
>a programmer needs to write effective code

effective is not always little code, and in quite a few cases especially with embedded systems you should write your own functions just so you can think about the final product and how much each line is gonna cost you in the long run
>>
>>59728625
if they are mainly targeting x86 why do they care about portability then?
>>
>>59728647
i do not know c++ math libraries still use macros instead of templates and they are pretty effective
>>
>>59728659
It's about writing the minimum amount of code that gets the job done. Yes, in embedded systems where you can't afford to waste hardware resources, it can make sense to write custom functions, if none of the existing tools meet your needs. Otherwise, if your code doesn't need that level of performance optimization, focus on getting your program to work as a whole first, and then worry about applying optimizations to problem areas.
>>
>>59728676
The idea being that a demand for porting it to ARM might appear later on, after the code is written.

>>59728696
std::vector uses templates, it would be virtually impossible to create that sort of generic data structure with macros.
>>
C beginner here - what is the most accepted method to use when you need to create an array of unknown size?

Like say, number of primes under a certain number. I would generate the primes, and would I then use reallocation to change the size of the array I'm putting them in if I go over the limit?
>>
>>59728647
will look into realloc. ty
>>
>>59728703
no even IF those functions exist you would want to make your own

that is EXACTLY THE PROBLEM with software engineers and why i do not consider them engineers, you faggots do not care about performance you just care about having it work and then never improving on it which is NOT engineering, you have to improve that you already have to pretty optimal levels before making something new
>>
>>59728718
it would not i did it once to troll my software engineering class at the university i also used gotos instead of loop structures, with unions to see how many will be stupid enough to hand it in
>>
int process_array(char array[64])
{
return sizeof array == sizeof char *;
}


REEEEEEEEEE

I would have preferred them not to allow array arguments at all, than to allow them as misleading bullshit syntactic sugar for pointers.

Luckily, there's a solution that actually makes your code clearer.

struct username {
char name[64];
};

int is_admin(struct username user)
{
return strncmp(user->name, "admin", sizeof user->name);
}


This is nice because what we want is a username, not an array of char that happens to be some magic size.
>>
>>59728724
Problem is you need to store the primes in the meanwhile, before resizing the array. Possible there is some algorithm to efficiently calculate the number of primes in an array, before actually calculating what those primes are - idk, not a math person. Otherwise you could do something that works kind of like std::vector, maybe allocating an initial array for 50-200 elements, and growing it by X% every time it gets Y% full. And if you really don't care about speed you could always do a linked list or stack that does a seperate malloc call for each element.
>>
>>59728759

Whoops, should have been
struct username *user
or
user.name
.

Eh.
>>
>>59728310
C is really just one big macro for assembly

and in assembly nothing is done for you
>>
>>59728733
Getting it to work in the first place is more important than getting it to work perfectly the first time. The people who make libraries devote their efforts to making something that performs well for a variety of standard use cases. Sure, write your own code if libraries don't meet your needs, but unless you're really pushing your hardware to its limit already, don't focus on reinventing the wheel when someone's probably already done it better.
>>
>>59728718
and for that arm thing, if you know you suspect you might port it to other architectures you typically write in a risc style
>>
>>59728797
that is what subpar programmers say, a good programmer knows algorithms and datastructures enough that he can make the code fairly effective on the spot without even trying that much
>>
>>59728733
not all software engineers are like that

I always try to optimize my code as much as I can before I consider a project finished.
>>
>>59728762

Well, we're talking integers here, and I don't think this specific example should be too much for the average computer to handle - I would probably get away with just generating a huge array in 99% of cases.

But I figure if I'm handling it all manually from the start, I might as well do it properly - the percentage thing seems like the best thing to do.

It's going to be annoying having to consider that C doesn't know how big an array is either - I'm so used to MATLab and just having a function and well-defined objects for everything, its definitly a big adjustment.

Thanks, by the way!
>>
File: 1490469016833.jpg (145KB, 405x400px) Image search: [Google]
1490469016833.jpg
145KB, 405x400px
>>59720382
>During ancient times, counting to 10 was a big deal and a person who could count to 10 was considered to be "wise".
You're absolutely retarded
>>
>>59720382
>Popular search engines such as Google, Bing, Yahoo!, Wikipedia, Amazon, YouTube and Baidu are used to calculate the ratings

>C doesn't have resizable arrays
Yes it does

>C doesn't have strings
>C doesn't have string concatenation
Yes it does

>C doesn't have namespaces
Not manual ones but that's precisely what you want with C, no surprises in embedded code.

>C doesn't have memory safety of any kind
MUH SAFETY, go use Rust you fucking cripple.

>C doesn't have meta programming
>What are #define's?

>C doesn't even have string switches
Because you can't jump table that shit you ding.
>>
>>59720171
No templates
>>
it is in english
>>
>>59727623
The majority of blogs run by hiring staff:

>If you can clearly explain your thought process I don't care if you forgot half of the syntax

/g/:

>not only does the syntax have to be perfect but you also have to know my preference for whether you should use a library function or write it your self, don't guess wrong

I'm glad these basement dwellers will never be in a position to actually impact anyone.
>>
File: h-1-0126-bilbo-baggins.jpg (43KB, 400x300px) Image search: [Google]
h-1-0126-bilbo-baggins.jpg
43KB, 400x300px
>>59729142
>resizable arrays
VLA's are considered such a misfeature that they were made optional in C11.

>namespaces
>Not manual ones but that's precisely what you want with C, no surprises in embedded code.
Oh fuck off, it wouldn't affect embedded code one iota. C++ uses name mangling to implement namespaces, and these mangled names are only visible to the linker. The resulting machine code, properly stripped, has no trace of them and doesn't know any different.

>meta programming
>What are #define's?
C macros are string substitution, basically one step above running your source through sed beforehand. Templates are better and safer by every measure.

Whoever made that comment about hacker LARPing in /g/ was right. Fuck outta here.
>>
>>59729142
The lack of namespaces and member functions in C does bother me sometimes, but I really wish they could be implemented in a way that doesn't fuck up name mangling and so on. Basically namespace::function would become namespace_function and object.memberFunction(arg1, arg2) would become typeof(object)::memberFunction(&object, arg1, arg2) and then be transformed by the aforementioned namespace mangling rules. Of course, the "typeof" would be resolved at compile time, so there wouldn't be any need for type information in the binary.

I suppose I could probably implement something like this over C using a custom preprocessor, though at that point I'd probably be basically reinventing cfront.
>>
>>59729579
Namespaces WOULD affect embedded code, like anything else, if you're using object files from multiple compilers.

And you do realize that typical template usage is string substitution as well? You'd just need to append the output for each type to the end of the source file and apply name mangling yourself.
>>
>>59727724
>"C++ is too hard"
>t. Pajeet
>>
>>59729628
>Namespaces WOULD affect embedded code, like anything else, if you're using object files from multiple compilers.
C doesn't define an ABI, so this is already a theoretical problem anyway. In practice, there is standardization, and there's no reason new features couldn't also get similar bastardization.

>>59729628
>And you do realize that typical template usage is string substitution as well?
C++ templates have SFINAE, so wrong-headed overhead resolution doesn't kill the build.
>>
>>59729827
>C doesn't define an ABI, so this is already a theoretical problem anyway.
C was/isn't designed in a vacuum. They pay attention to actual implementation and what they're doing.
People understand that the C ABI is very important, and they're not just going to break it.

>>59729579
>VLA's are considered such a misfeature that they were made optional in C11.
No, that's not it. VLAs actually take a bit of effort to implement, and have very large consequences on the type system.
A lot of compilers (for embedded systems etc.) were complaining that they didn't want to spend the effort implementing something that they weren't going to use, so they made it optional. It's the exact same thing for complex numbers.
Compilers that support C99 and target desktop-tier CPUs or whatever are still expected to implement them.
>>
>>59728703
Different anon here: there are cases where I might agree with you. HOWEVER, most "engineers" today don't know the computer at a low enough level to even begin to assess when to use library functions and when to roll their own.

And if they did, they couldn't roll their own.

This plays out in subtle ways that lead to inefficient code even in high level languages. Most of my work has been in high level languages, yet my code tends to be faster/more memory efficient because even if I don't use C I'm looking at the code and thinking about how it's going to stream through the CPU and how it's going to access memory.

A lot of guys I've met code like every high level method maps to a single op code and memory access has zero cost.
>>
>>59728310
>why doesn't C just waste time for you?
>>
>>59729014
>Well, we're talking integers here, and I don't think this specific example should be too much for the average computer to handle

Array resizing is not etched into the silicon. So in a sense it is "too much" for any computer to handle. It's accomplished in higher level languages by library functions and/or OS functions which sometimes have to copy all the data from one range of memory addresses to another.

C does not hide this from you. Which makes you think about costs as you design your algorithm.
>>
>>59728511
Yes
>>
C++ is superior
>>
>>59720235
Explain.
>>
>>59731292
okay, so I did this and I still get output?

[spoiler]
#include <stdio.h>

void f1() {
int d=3, e=25, f=3;
// int a, b, c;
// a=1;
// b=2;
// c=3;
}

void f2() {
int a, b, c;
printf ("%d, %d, %d\n", a, b, c);
}

int main()
{
f1();
f2();
}
[/spoiler]


Can someone explain this to a noob?
>>
>>59731323
>[spoiler]
FUCK

#include <stdio.h>

void f1() {
int d=3, e=25, f=3;
// int a, b, c;
// a=1;
// b=2;
// c=3;
}

void f2() {
int a, b, c;
printf ("%d, %d, %d\n", a, b, c);
}

int main()
{
f1();
f2();
}
]
>>
>>59720543
Prettymuch this.

If C doesn't have it, you don't fucking need it. If you think you fucking need it, then you are are probably one of those half-retarded legbeards who likes to "code" in ruby.
>>
>>59721088
>"Churning out more shit" is the appropriate terminology since so much software today is in fact shit.
This right here is the sole reason behind my confusion, so many people are aiming for "more productive" languages to attain "more productivity". What the hell are you people producing, why do you need to produce it so fast? How about instead of turning out 10 clone projects made from the same libraries as your competition you turn out a single project that's actually worth something to someone and isn't just hastily(see:"productive") made "shit".

Acting like there's no time to work so they need to invent things to work faster to produce more things because they make no money because their shit don't sell. Ugh.
>>
>>59728759
>>59728775
Parens too
sizeof (char *)
>>
>>59728724
C doesn't have vectors, sorry.
>>
>>59729142
>#defines
>""""""""""Meta programming""""""""""
Good one. Also, why do C toddlers think their gimped version of macros are good for anything
>>
>>59731370

> you are are probably one of those half-retarded legbeards who likes to "code" in ruby

Ehem.

Ruby is written by C enthusiasts. A lot of Ruby libraries (called "Gems") even uses C extensions, which means you have parts of the library written in pure C.
>http://blog.zachallett.com/howto-ruby-c-extension-with-a-static-library/


Furthermore you can write pure C (and C++) with ONE single include:

require 'inline'

class InlineTest
inline do |builder|
builder.include '<math.h>'
builder.c '
int inline_pow(int a, int n) {
return pow(a, n);
}'
end
end

puts InlineTest.new.inline_pow(2, 10)



You can also include pur C classes.

And did you noticed how much the Ruby syntax was influcend by C (i.e. "puts" command, strings can be accesses as char arrays)?

>For example, I was a C++ programmer before I started designing Ruby. I programmed in C++ exclusively for two or three years. And after two years of C++ programming, it still surprises me.
- Matz, creator of Ruby

If anything, Ruby encourages the usage of C and C++, because it's tightly modeled arround it. Ruby is open source, so if you want to see beautiful C code, just take a look at the impressive Ruby classes..

[/rant]
>>
>>59720382
Did you just fucking copypaste all that shit from the thread from few weeks ago and put it all in one message?
>>
File: 1463196889481.png (97KB, 1934x1069px) Image search: [Google]
1463196889481.png
97KB, 1934x1069px
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 software industry. If you want guaranteed memory exploits and security vulnerabilities in your program with timesink development period then use Assembly, not C.
>>
File: c.png (85KB, 745x888px) Image search: [Google]
c.png
85KB, 745x888px
>>59731821
>>
>>59731833
>U dun need it, just implement basic data structures like strings brah
Instead of undefined behaviors in every functions I'd like to have strings
>>
>>59731850

So what string operations are so important and difficult that you can't just use <string.h>?

AFAIK strings are usually for I/O or storing data. Simply an information.

If you use Ruby for "quick and dirty" tasks (grab some file, filter lines with some regex, close it) and C for performance critical tasks, nothing is impossible.


Beyond that it's just a matter of personal language preference, some people prefer pizza, some people prefer sushi.

But if C is good enough for the NASA, then it's good enough for me, I guess. You just need apropriate standards for coding, testing and so on.

>http://lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf
>>
Half of the language is undefined behaviour :^)
>>
>>59720543
C is time sink:
>Implement your own string
>Implement your own vectors
>Implement your own array slicing
>Implement your own string concatenation
"I actually don't know what they are because C has taught me nothing but if-else-while-and-for.":
>Generics are "useless"
>Namespaces are "useless"
>Exeption handling is "useless"
>Use cpp, I know a little(!) about meta programming
"Don't have milk but I got soda":
>Use variadic function functions. (Does C have multi return functions?)

This is your brain on C(ancer). Basically, average C toddlers of /g/ has accomplished nothing bigger than a 500LoC fizzbuzz level projects and thinks the things that he hasn't used (because he doesn't know what they are) are not useful in actual, real world programming. If only these C toddlers ever had a job...
>>
>>59731909
https://modelingguru.nasa.gov/docs/DOC-1439/version/6
>>
File: stack.png (16KB, 982x721px) Image search: [Google]
stack.png
16KB, 982x721px
>>59731337
When f1 is called, the values 3, 25 and 3 are pushed on to the stack, f1 does nothing else so it returns and its stack frame is destroyed. Now f2 is called and its stack frame is created on top of f1's destroyed frame. f2 declares three variables but doesn't do anything to their values, therefore their value is what happens to be in that memory area. In this case they happen to be the three values that f1 "left behind" on the stack.
>>
>>59731833
http://s.4cdn.org/css/tomorrow.css
There you go f_a_m, copy that into the Custom CSS Edit field in Settings -> Miscellaneous

Also be sure to enable the native extension checkbox
>>
>>59731930

You don't really get it..

>I need some simple I/O
Use char arrays.

>B-but I need advanced sting functions
Then use something like <string.h> or <regex.h> or what you need.

>But I want maximum String manipulation, I NEED string classes..
Then you can either make your own strign class with your custom functions or use other libraries.
>>
>>59731930
>toddlers...jobs...toddlers...jobs
Your projection is showing.
>>
>>59720171
no generics
>>
File: 1487987157828.png (577KB, 911x683px) Image search: [Google]
1487987157828.png
577KB, 911x683px
>>59720171
For 80% of applications (especially /g/-tier applications) it's a waste of time for little gain usually fetishized by bikeshedders and hobbyists more obsessed with projecting virtue into their code than actual functionality, maintainability and portability.

Not to mention the stuck-up retarded purists who won't shut the fuck up about how they're "real programmers" when they're basically using a language that, when viewed through the same lens they view higher-level languages through, is for people too dumb or lazy to learn assembly, since it's not like whatever shit code they write is going to be portable anyway.
>>
>>59732061
>when viewed through the same lens they view higher-level languages through, is for people too dumb or lazy to learn assembly, since it's not like whatever shit code they write is going to be portable anyway.
butthurt much?
if you have ever used assembly you know how C is a million times faster to work in while providing at worst identical performance
>>
>>59732090
>butthurt much?
No, just realistic. You aren't special.
>if you have ever used assembly you know how C is a million times faster to work in while providing at worst identical performance
You could say the same of many higher-level languages for many tasks, which is my point.
>>
>>59732090
>I suck at ASM
Yeah everyone knows, yet you chose C over ASM but bitch about performance. Fuck off, idiot C toddler
>>
C apologists are NSA shills plain and simple. Rust makes it harder to produce vulnerable programs as it actually implements safety precautions like Bounds checking, dangling pointer prevention, data race prevention, lifetimes etc. This is against the interest of the NSA and so they are shilling C so that people continue to produce exploit prone, unsafe and vulnerable programs.

Ignore the NSA/C shills. Programming in C should be banned and outlawed.
Say no to security exploits, say no to the NSA. Your data and your privacy is worth preserving.
>>
>>59731971

It's clearer when you do it like this:

#include <stdio.h>

void f1() {
int x=1;
}

void f2() {
int a, b, c;
printf ("%d, %d, %d\n", a, b, c);
}

int main()
{
f1();
f2();
}



Most implementations will show you something, because you point to "somewhere". It does exactly what you told the programm to do, don'tt blame C for doing retarded stuff.
>>
>>59732131

> t. Klabnik
>>
>>59720171
pointer syntax
>>
>>59732174

Sorry, meant for:
>>59731337
>>
>>59732116
>You could say the same of many higher-level languages for many tasks, which is my point.
Higher level languages almost never have identical performance to C. They're identical only when constrained by some external factor (i.e. I/O), or when a narrow use case has been tightly optimized.

He wasn't right to say C has worst case performance equal to assembly. You can sometimes make even further optimizations in assembly. But C is damn close, equal much of the time, and much, much faster than any higher level language.
>>
>>59720186
>>59721166

Is not Assembly
>>
You cannot write a function that adds two numbers from a user in C.

It's a pretty shitty language
>>
>>59731971
>>59732174
Thanks!

So if I inititialized them to some value this wouldn't have happened, right?
>>
>>59732219
#include <stdio.h>
int main(){
int a, b;
printf("Please enter two numbers separated by a space: ");
scanf("%d %d", &a, &b);
printf("%d\n", a+b);
return 0;
}
>>
>>59732268
>int
When did I say integers? And your piece of code doesn't solve anything I described
>>
>>59732205
>Higher level languages almost never have identical performance to C.
I wouldn't say that's always the case, a language like FORTRAN for example will kick C's shit in depending on the workload, and for the most part the performance differences are imperceptible or otherwise fuck all when compared to the benefits a safer, more understandable and thus maintainable program can bring.

>He wasn't right to say C has worst case performance equal to assembly. You can sometimes make even further optimizations in assembly. But C is damn close, equal much of the time, and much, much faster than any higher level language.
You should notice that I said "through the lens of", I also agree that a good compiler will rip you a new asshole 9 times out of 10, but if I was a retarded shitposter I could also just use the same cop-outs others are employing in these threads and just say you're shit at it and need to get good, because once again, programming to some is all about being holy and virtuous, not actually making something useful.
>>
>>59732268
Nice memory vulnerability

>C
Oh I should've expected that
>>
>>59732283
>When did I say integers?
I had to assume because you can't communicate worth shit.

>And your piece of code doesn't solve anything I described
>"adds two numbers from a user"
>program does that
>"doesn't solve anything"
You mouthed off on a message board about a language you have never touched and got called out on it. Now STFU.
>>
>>59732327
>I had to assume
Why did you assume the users will input integers? Do you think they will consider your lack of competence because you use C? I don't think so.

Now quickly write a function that adds two numbers entered by the user and returns the sum of them. I will judge C's correctness based on your reply
>>
>>59732292
>>Higher level languages almost never have identical performance to C.
>I wouldn't say that's always the case, a language like FORTRAN for example will kick C's shit in depending on the workload,
Not really. The only intrinsic advantage is that Fortran doesn't allow pointer aliasing (or rather assumes the programmer does not allow it). To match this you have to make use of strict aliasing in C.

>and for the most part the performance differences are imperceptible or otherwise fuck all when compared to the benefits a safer, more understandable and thus maintainable program can bring.
Is that why we have bloated, slow, shit code?

I'll admit that each project requires a balance of considerations and often a higher level language is a better fit due to considerations other than raw, balls-out speed.

HOWEVER...that line of reasoning (or memeing) has led to abominations like Java, Haskell, and Scala and to a generation of lazy programmers producing "Enterprise software stacks" that are bloated beyond belief. I mean holy fuck, Poosoft just got called out because they shipped a code editor with a blinking cursor that consumed 13% of a modern, multi-billion instruction per second processor.

Just fuck my performance up.
>>
>>59732323
Where do you see a vulnerability in that code?
>>
>>59722402
>Comes to /g/ and expects anything but autistic bullshit

The only one that fucked up here is you.
>>
>>59732388
Ah, the smell of FRESH C toddler kiddies, I jerk of to them every single night
https://en.wikipedia.org/wiki/Uncontrolled_format_string#Details
>>
It's low level. This can be a flaw in many applications. Key word is can.
>>
File: webcam-toy-photo1.jpg (74KB, 800x600px) Image search: [Google]
webcam-toy-photo1.jpg
74KB, 800x600px
>>59732425
>low level
>flaw in many applications
It is NEVER a flaw to program at a low level. There usually are easier alternatives, but you give up control to do so.
>>
>>59732323
>hurr durr i'll shit post about a language i know nothing about
scanf doesn't buffer overflow reading an int you idiot. If you use %s to read a string, specify the max width:
scanf("%10s", &s);
>>
>>59732462
>scanf doesn't buffer overflow reading an int
Aww C toddler thinks malicious users will enter ints because (s)he told them to :3
>>
>>59732447
How quickly can you whip up something that applies NLP to news articles linked in a forum in order to understand whether the consensus outlook is positive or negative?
>>
>>59732475
>(s)he

>>>reddit
>>
>>59732352
>use doubles "Why do you assume the user won't input big numbers?"
>use a big number library "Why do you assume the user won't input English numbers?"
>parse English text "Why do you assume the user won't speak Spanish?"
KYS

>>59732415
>link to something that's not relevant
scanf does not buffer overflow on numeric specifiers. And I did not supply user input as a format string to printf.

Now go to bed toddler.
>>
>>59732482
Doesn't matter, C toddlers make me cum regardless. Thanks for paying my bills with your shitty 'c' ode
>>
>>59732489
C doesn't have native UTF, so let's not go there.
But can you actually add two user defined numbers in C?
I don't think you can. Prove me wrong if you can, sweetie
>>
>>59732494
>trying this hard
>>
>>59732475
It doesn't matter what the user enters you fucking idiot. scanf will not write more than 4 bytes (sizeof int) to the variable on that specifier.
>>
Java is better.
>>
>>59732503
Already did fattie.
>>
>>59720171
Not used by corporations
>>
>>59732513
>Already did
Your program can add integers only, that's not what I wanted you to do. Are C tards retards?
>>
>>59732529
I don't care what you want. You made a ridiculous claim and now are trying to move the goal posts to save face.

Want doubles? Change the variable types and specifiers.
>>
>>59723142
>It's a wanton abuse of undefined behavior to make a nonissue look like some sort of security flaw.
I mean it's not a security flaw, but it's totally a UI flaw for the poorly initiated. The thread's OP called for 1 flaw.
>>
>>59732543
>I don't care what you want
Are you upset? I guess you are. Failed programmers become upset so easily.
>You made a ridiculous claim
Adding two user defined numbers is "ridiculous"? I think even a 5 year old toddlers can do it. Why not a C tard?

>Want doubles? Change the variable types and specifiers.
C has compile time code generation? Wow, that's a nice "useless" high level feature. Wanna explain why C is so inconsistent?
>>
File: 66d.png (387KB, 500x402px) Image search: [Google]
66d.png
387KB, 500x402px
>>59732543
>>59732529
>>
>>59720171
Hard to learn
>>
>>59732572
From what I've gathered, C fanboys of /G/ are entry level programmers or novice/learners.
>>
>>59732415
>>59732462
As far as I know, you're full of shit. Stop beating around the bush and post an example of how you're going to exploit his code. Tell me what exactly you're going to input because as far as I know scanf is going to stop the moment it reads something that isn't whitespace or a digit, so what exactly are you going to pass it?
>>
>>59732580
All /g/ NEETs are shit programmers regardless of their language of choice.
>>
>>59732579
C is a beginner level language designed for lesser programmers with low attention span that cannot think big.
>>
>>59732594
>beginner level language designed for lesser programmers
But It's python.
>>
>>59732598
That's no different than C. Read a 300 page book and call yourself a "programmer" like the C tards ITT
>>
File: 2372.jpg (31KB, 598x448px) Image search: [Google]
2372.jpg
31KB, 598x448px
>>59732571
>but it's totally a UI flaw for the poorly initiated.
Initializing variables consumes processor time. C does not hold your hand. If you want initialized variables, initialize them, otherwise C is not going to waste op codes and memory on it.

>>59732572
>making up shit to sound clever
See the pic? Good.

>>59732590
>Stop beating around the bush and post an example of how you're going to exploit his code.
He can't because there is no vulnerability using scanf with numeric specifiers. He just spouted a meme because "hurr durr i hate c y won't everyone use java."
>>
>>59732385
>Not really. The only intrinsic advantage is that Fortran doesn't allow pointer aliasing (or rather assumes the programmer does not allow it). To match this you have to make use of strict aliasing in C.
I'm not going to blow smoke up your ass and say I know the specifics, I've merely heard great things about it every time the subject comes up.

>Is that why we have bloated, slow, shit code?
I wasn't really trying to imply bad programming practices don't still exist, in fact it's one of the main reasons I don't believe languages like C to be omnipotent.

>HOWEVER...that line of reasoning (or memeing) has led to abominations like Java, Haskell, and Scala and to a generation of lazy programmers producing "Enterprise software stacks" that are bloated beyond belief.
But unfortunately, shit practice has been endemic to the field since debuggers were a bunch of incandescent lights, and it will continue to be so for centuries to come. In the end I'd rather make it easier for that down syndromite intern to write something safe and readable that I can fix easily when it gracefully crashes than to deal with cleaning up the mess from a fucky bounds check or poor memory micromanaging even if it meant a slower but still usable product.
>>
>>59732665
>making up shit to sound clever
I'm not. Now re read >>59732572 very carefully and post your best damage control.
>>
>>59732673
>But unfortunately, shit practice has been endemic to the field since debuggers were a bunch of incandescent lights,
Except that's not true. Code quality has definitely gone downhill since the early to mid 2000's.

>In the end I'd rather make it easier for that down syndromite intern to write something safe and readable
That's not happening either. "Safe" languages are not safe. They may catch the dumbest of mistakes but there are still plenty of pitfalls lurking in them.

And shitty coders produce unreadable code in ANY language.
>>
>>59721341
Is Go a worthy replacement for C?
>>
>>59732705
Only if you are a massive shill.
>>
>>59732219
No one is able to refute this yet. What a shitty language C is hahaha
>>
>>59732598
>>59732602

C:
-syntax to remember: little
-exectuion speed: very fast
-skills for building complex applications: intermediate to pro (understanding of complex data structures)

Python/ruby:
C:
-syntax to remember: little
-exectuion speed: medium-slow (depending on the task)
-skills for building complex applications: beginner to intermediate (language protects you from your own stupidity)
>>
>>59732765
>Python/ruby:
>C:
wtf is wrong with you?
>>
>>59732705

It was planned that way originally, but they back paddled a big deal (google "Golang systems language").

Today the consensus seems to be that Go is a kind of "Entry level C" with more emphasis on the web than C. It's a soft landing when you only know Java and want something more deep, but it is not as powerfull as C, because it (intentionally) skips some of C's killer features.

Bascially it boild down to picking two of the following:
(1) Performance
(2) Little Syntax, easy to use
(3) Higher abstraction

C has (1) and (2)
Rust and C++ have (1) and (3)

And then there's a lotof languages that somehow try to be a middle ground.
>>
>>59732771

Chill out, it was a typo.
>>
File: gmp.png (31KB, 489x628px) Image search: [Google]
gmp.png
31KB, 489x628px
>>59732721
Okay, here's my attempt.
#include <stdio.h>
#include <gmp.h>

int main(void)
{
mpf_t first, second, res;

mpf_init(first);
mpf_init(second);
mpf_init(res);
printf("Input two numbers: ");
mpf_inp_str(first, stdin, 10);
mpf_inp_str(second, stdin, 10);
printf("Their sum is: ");
mpf_add(res, first, second);
mpf_out_str(stdout, 10, 0, res);
}
>>
>>59732945
>7 undefined references in one program that adds two numbers
Truly, C experience
>>
>>59732964
My bad, should've mentioned that you need the GNU Multiple Precision library and you need to compile with -lgmp.
>>
>>59720171

The preprocessor, which was not initially designed for C.
>>
Without C embedded programming would be shit. Imagine learning ASM for all AVR and ARM chips.
>>
>>59732977
>Scientific notation
Why are you giving me that? And how do I input 1*10^e?
>>
>>59720171
Ok here is a none meme flaw
>Implicit cast from array to pointer
Arrays holding their length statically would solve so many buffer overflows.
>>
>>59732219

You cannot use pointer arithmetics in [your language here].

It's a pretty shitty language.
>>
>>59733012
>nonsensical response
Hello, postbot.
>>
>>59733028
>Rust, D and C++ can't do pointer arithmetics
Show proof.
>>
>>59733041
No, I didn't use scientific notation in the input, why are your outputs in that from?
>>
>>59733012
>Why are you giving me that?
Output of the format was not specified. Scientific notation allows for short output (0.123e40 instead of 123000...000000).
>And how do I input 1*10^e?
It adds two numbers, 1*10^e isn't a number but rather an expression, so you need to calculate the number it evaluates to (with some precision).
>>
>>59733076
>1*10^e isn't a number
Uh?
https://www.google.com.au/search?client=ubuntu&channel=fs&q=1*10%5Ee&ie=utf-8&oe=utf-8&gfe_rd=cr&ei=_XvjWP3OH8zN8gf42ZSABA
>>
>>59733090
I stand by what I said, 1*10^e is an expression that evaluates to the number 522.73529967.
>>
>>59733131
So is 1*10^2, which evaluates to the number 100. Does you program do that? No? Thought so.
>>
>>59733139
The specs said it should be able to add two numbers, not parse symbolic expressions. If you want support for that, you can use for example this library https://www.gnu.org/software/libmatheval/
>>
>>59733172
If your program cannot support parsing why would you format the output that way? Did C teach you to leave program unfinished like the language itself?
>>
>>59733218
C is such a timesink, programmers struggle to come up with a half working solution in time
>>
File: output.png (12KB, 502x144px) Image search: [Google]
output.png
12KB, 502x144px
>>59733218
Fair enough, this will output in decimal notation.
-mpf_out_str(stdout, 10, 0, res);
+gmp_printf("%.*Fg", 100, res);
>>
>>59733403
test with 4.9 + .1
Thread posts: 325
Thread images: 31


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