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

C vs C++

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: 145
Thread images: 8

File: canyouCthedifference.png (20KB, 488x441px) Image search: [Google]
canyouCthedifference.png
20KB, 488x441px
Why would you want to learn C over C++ when C is a subset of C++?
>>
It's lower level
>>
>>62007532
>2 arrays
>2 strings
>3 standard libraries
>still no modules
>>
it's not a true subset. and it depends what you are programming for. sometimes C is called for over C++.
>>
>>62007544
shame he didn't look at the picture.
it shows that its not a true subset, see the red bit on the left?

also >>62007532 not every platform has a C++ compiler. Sometimes when they do, it produces really shitty code, or is only compliant pre C++11.
>>
>>62007532
A simpler mechanism is less likely to break
>>
>>62007532
>clearly c and c++ only intersect
>C is a subset of C++
Is this the kind of math universities teach to compsci majors?
>>
>>62007544
What is an example of where C would be better suited over C++? And how often might this be the case if C++ has so many of the same features.
>>
>>62007580
When you refer to C as a simpler mechanism do you mean that C++ has too many unnecessary features that might complicate a program being developed in it?
>>
>>62007572
My mistake, I just heard that terminology thrown around before and just assumed without even thinking about the picture. So if C++ has the majority of the features C has, and then some, what does C exclusively have that would want someone to learn it over C++?
>>
File: fatgirlflow-313679.jpg (50KB, 590x456px) Image search: [Google]
fatgirlflow-313679.jpg
50KB, 590x456px
>>62007532
pic-related is a subset of a hottie.
>>
>>62007704
c++ has a lot of ways to do the same thing. can be confusing to read
>>
Idiomatic C and idiomatic C++ look and behave very differently. Beware those who say they know C/C++, they know C and objects.
>>
>>62008578
Are you saying that most people don't idiomatically use C++ and instead borrow most concepts from C leading to an inefficient program?
>>
>>62007535
/thread
>>
>>62008679
>Are you saying that most people don't idiomatically use C++ and instead borrow most concepts from C
Yes

>leading to an inefficient program?
An unmaintainable program
>>
For the same reason you don't want cancer even though cancer cells are a subset of your own body tissue.
>>
>>62008741
Is this an argument against C++ as a language or just saying that most that have used both have not used C++ properly and are therefore unqualified to comment?
>>
>>62008882
Neither, really. It's that people who think applying their babby's first OOP knowledge to C means they know C++ are going to write awful C++
>>
>>62007535
>>62008733
What if you don't need lower level as it would take more development time but still desire a faster program than most other high languages could provide?
>>
>>62007532
What about C#?
>>
>>62007532
Because you only want/need that subset?
>>
>>62008933
Java and C# would be analogous.
>>
>>62007532
You need to program a bit more so you can answer this question by yourself.
>>
>>62007532
My logic is that I will turn to C++ when I can't do it in C.
But I haven't encountered that situation yet.
>>
>>62008882
>>62008902

Using C++ "properly" is not just a matter of common sense. It's an incredibly complicated language that was put together in an inconsistent ad hoc manner.

Even PHP has unironic defenders. I can't remember the last time a C++ dev was apologetic. Industries where it's a necessary evil are more than dying to get rid of it, Rust was being used internally in game development companies before 1.0 even came out.
>>
>>62008930
only niggers ask hypothetical questions.
>>
>>62008984
Do you use it for work or personal projects?
>>
>>62008958
What capabilities does it provide that C++ doesn't, or what does it do better?
>>
File: BitKu_2017_06_03_CREATION.png (5KB, 432x432px) Image search: [Google]
BitKu_2017_06_03_CREATION.png
5KB, 432x432px
>>62007532
Learning C. You can't stop me.
>>
>>62009074
Not trying to stop you friend, what influenced your decision to learn that particular language?
>>
>>62007535
You can quite literally write C code in C++ with a few modifications. And these modifications make a better more secure program

This is why Linux comes out with a new major exploit so often.
>>
>>62009160
>better more secure
wow. got a powerpoint to go with that?
>>
>>62009160
wut
>>
>>62009160
>This is why Linux comes out with a new major exploit so often.
Major exploits are inevitable. The only difference is that free software raises public awareness of them and is concerned first and foremost with resolving the issue as fast as possible.
Windows is laden with serious security issues, but Microsoft doesn't do jack shit to warn people.
>>
>>62009171
>>62009223
>>62009236
Man just look at OpenSSL. A fucking buffer underflow was able to cause worldwide panic. And it's written in C

C++ strings would have saved the day
>>
I use C-style C++ for my projects because it's simpler and easier to understand and maintain.

Terry Davis does this too: https://github.com/minexew/TempleOS/blob/master/TempleOSCD/Downloads/Linux/TOSZ.CPP
Terry Davis says that modern C++ is too complex.
>>
>>62009251
>A fucking buffer underflow was able to cause worldwide panic.
The media will take any excuse they can to start mass hysteria for better ratings and ad revenue. What actually happened was they hopped on the bandwagon after infosec nerds attempted to make the issue as visible as possible for the community's sake. Whenever proprietary software has a severe vulnerability, in comparison, you don't hear it from the vendor, it gets announced by a group of white hats or makes headlines when millions of boxes get rekt out of nowhere.
The NSA meme is actually true, by the way. https://en.wikipedia.org/wiki/EternalBlue
>C++ strings would have saved the day
C++ would have led to five different bugs of equal severity, and they would likely never have been found except by hackers smart enough to abuse them without raising red flags.
>>
>>62009325
>c++ would lead to 5 different bugs of different severity
The only bugs C++ is more common for having are maybe compile time issues
C++ is purposefully half bare metal and half high level. Low level is the one that creates bugs of as severe as heartbleed because of carelessness on the programmer's behalf
Show me one exploit in C++ that would have been solved by using C

Also
>implying no person used the exploit before it got publicized
How amazing would it be to be as innocent as you
>>
>>62009309
Why not just use C then? Do your projects require features that only C++ provides?
>>
>>62007535
No it isn't.
>>
>>62009513
Isn't C considered a mid level and C++ a high level?
>>
>>62009529
No.
Both C and C++ are equally low level.
The difference between C and C++ is that C++ can efficiently go high level while C can not.
>>
>>62007580
Is this why C causes the most security exploits?
>>
>>62009553
c is not low level. assembly is.
>>
>>62009567
It's subjective.
There is no point in arguing it.
>>
>>62009446
>The only bugs C++ is more common for having are maybe compile time issues
They are a large share of them, but you're insane if you think they are "just" compile time issues. Debugging C++ is like trying to find a needle that could be in any haystack in your country.

>Show me one exploit in C++ that would have been solved by using C
If you can make claims without evidence, so can I. :^)

>>implying no person used the exploit before it got publicized
Is that seriously your argument? It's been demonstrated numerous times that free software deals with security fiascos profoundly better than proprietary software does.
>>
>>62009553
With this in mind, is there a use where C is more practical than C++? C++ seems better if it can switch between levels.
>>
>>62009599
>They are a large share of them, but you're insane if you think they are "just" compile time issues
Proofs
>If you can make claims without evidence, so can I. :^)
Hurr durr a underflow in a char array wouldn't be solved by using a string class
I'm still waiting for ONE example where C would be more secure where C++ would not
>Is that seriously your argument?
You downplayed the severity of the exploit nearly claiming that it wasn't as severe as thought. My claim was that your claim is bullshit in that people might have used it before it was publicized
Try to keep up. I know that writing C might have mentally disabled you, but adults are speaking
>>
>>62009638
The only advantage C has over C++ is that C has non-trivial designated initializer-lists, which are sometimes really useful when hardcoding large sparse static arrays.
This is entirely the fault of the committee.

Other than that, no. Whatever C can do, C++ can do better.
>>
>>62009716
Why is C still in use then, is it mostly legacy support? it still seems more popular on embedded systems too.
>>
>>62009784
Legacy, and people who refuse to move on to better things.
>>
>>62009698
>Hurr durr a underflow in a char array wouldn't be solved by using a string class
Which has literally never been implemented in a stable free library. Ever.
>You downplayed the severity of the exploit nearly claiming that it wasn't as severe as thought.
Let me put it this way: a single person is randomly murdered. The media inflates this into claims of impending mass genocide. Pointing out that this is a gross exaggeration is not rationalizing or playing down violent crime, and it is grossly disingenuous to pretend otherwise.
There is literally nothing the media will not mischaracterize.
>My claim was that your claim is bullshit in that people might have used it before it was publicized
And your claim is not related to my argument, so it is moot.
>>
>>62009815
Is there a language you recommend learning over C++ or are there any notable challengers?
>>
Ignoring how you're wrong on the relationship between C and C++.
>why would you learn a subset over a superset
Because they're different levels of effort. You could learn electronics, or you could learn physics.
One is mostly a superset of the other much like C and C++. But learning physics broadly to the point where you can do electronics well compared to the focused attention on just electronics will take way more time.

Also I find your image misleading.
You should bloat the C++ so that the C portion almost vanishes. More accurate.
C++ is a very very large language now.
>>
>>62009892
Probably the best competitor to C++ is Rust, but they completely ruined it with the borrow checker and immutability by default.
>>
>>62008989
C was used in more games than rust. Name one game in rust
>>
>>62007532
I only code for micros, I don't need higher level shit C++ offers.
>>
It's not a subset of C++ you mong

Also C++ has a giant fucking standard library, a giant fucking compiler, and giant fucking binaries. A lot of its features are overkill or downright promotive of being shit at programming (Boost).

That's why C excels over C++ in embedded environments and performance critical applications or simulations.

However, C++ excels in very large and complex projects which need performance (i.e. web browsers and games) because of its object oriented nature, which suits it to large groups of programmers who maintain a large code base.
>>
File: 1483681636832.png (87KB, 853x621px) Image search: [Google]
1483681636832.png
87KB, 853x621px
>>62007532
why would you want to eat candy over candy covered in shit when candy is a subsed of candy covered in shit
>>
>>62009784
So are you saying that C++ will suffer the fate of Fortran?
>>
>>62009044
>>62009638
>What can you do in C but not C++?

In C, this program
int main ()
{
int new = 5;
int class = 5;
return new - class;
}

compiles.

In C, this program
#include <stdio.h>
int main ()
{
auto a = 1.7;
int b = a * 2;
int c = sizeof('a');
printf("%d,%d", b, c);
return 0;
}

outputs "2,4", whereas in C++ it outputs "3,1".
>>
Just use Java, lol.
>>
>>62010546
lol why do u need that old shit use jquery
>>
>>62009448
Classes. It's a hassle to achieve the same effect with function pointers.
>>
File: cube.png (289KB, 680x517px) Image search: [Google]
cube.png
289KB, 680x517px
>>62009156
Project
Compenents:
>ESP32
>IMU/Barometric modules
>Leap Motion "LM to esp32 still tricky"
>Acrylic screen microprojector
>Apache server to ssh/vnc to esp32 thru wifi
End Game is a sturdy headset AR HUD with a "game enviroment" composed of Latitude,Longtude arbitrates from google maps data. First and formost, It's just a device to connect to a pc and have a screen "Unity-Sortof Window manager program" in a "polarized (r^ 2 dr dtheta ) 3d context.
>>
>>62010322
Rust
>>
>>62011754
mind = blown
>>
>>62007532
The ideal case is indeed learning C++, as it's more featured, but learning how things are done in C avoids you from doing a complete unreadable undebuggable class mess.
>>
>>62007532
>learn C over C++
What's the problem to learn both and use one which is better suited as a tool for a problem as white straight privileged people do.

Programming languages are not rocket science if you don't learn them from theoretical computer science perspective and denotational semantics.

You'd better learn automata and compilers and other fields who teach you how to solve problem sets instead of focusing on a some particular tool.
>>
>>62008080
It's called superset, if you don't even know set theory then what do you need C for.
>>
>>62007532
>Why would you want to learn C over C++
Why do you have to learn one or another? Why not just learn both.

>when C is a subset of C++
C is not a subset of C++, it's an entirely different language with its own set of paradigm and idiomatic practices.
>>
>>62007535
C++ is just as low level as C, if you want it to be.
>>
>>62010500
>A char literal is an int
Cniles will defend this
>>
Why would you eat good food over anything including shit when good food is a subset of anything including shit ?
>>
>>62009563
Retard.
>>
>>62007542
So?
Would you prefer to remove stuff and which one would you prefer?
The safe or the fast option?
Why not give programmers options?
>>
>>62013526
Most programmers are too dumb to select the right tool for the right job.
>>
>>62007532
They compile to the same thing. The same fucking instructions. Adding a bunch of keywords and calling it `features' doesn't magically make your hardware do imporssible things.
>>
>2017
>have rust
>still using C or C++
>>
>>62009563
C causes most security exploits in C written programs.
>>
Your own chart literally says it is not a subset.
>>
>>62013549
they dont actually compile to the same thing, C is easy to use for kernels because it's easy to know what it will compile, whilst C++ uses some more higher level features of an OS
>>
>>62013548
most humans are too dumb to do menial tasks, yet the world still goes on.
Pointing to libraries as if it is evidence of flaws in a language also proves you are too dumb to program.

>>62013616
C can use the OS API as well and stuff like easy access to threads, is obviously not what you would do if you write applications to a platform without an OS.
In those cases you need to adhere to a lot stricter programming style, but you can still make an OS in C++ if you want to.
>>
>>62010500
except this wont compile in c because of auto keyword, keep trying retard
>>
>>62013775
auto is a storage specifier rather than doing type inference. The type is assumed to be int, so you get a silent narrowing conversion.
no idea what storage it actually specifiers though
>>
>>62013799
c doesnt have auto kayword, it doesnt matter what it is, it wont compile
>>
File: Screenshot_2017-08-21_12-39-14.png (40KB, 656x292px) Image search: [Google]
Screenshot_2017-08-21_12-39-14.png
40KB, 656x292px
>>62013809
>c doesnt have auto kayword
It does.
>>
>>62013809
It does.
http://en.cppreference.com/w/c/language/storage_duration
and it's implied unless you use register/static/extern
>>
>>62007535
no it's not
>>
>>62010500
I never used this before, but why is a and b not the same in C?
In C++ they are.
#include <stdio.h>
int main(){
char c = 'a';
int a = sizeof(c);
int b = sizeof('a');
printf("%d, %d", a, b);
return 0;
}
>>
>>62013844
what if I use?
Static auto wroomwroom
>>
>>62013909
char literals are considered integers in C
>>
>>62013548
dumbest response of the day. By that logic when you go the restaurant you shouldn't get any options cause people are too dumb to choose.
>>
>>62013909
A char literal is an int in C.
char c = 'a';

This is a silent narrowing conversion.
>>
>>62013951
>This is a silent narrowing conversion.
Aka truncation.
>>
>>62010500
thankfully c programmers are not retarded enough to write such code, theres literally no c library that wont compile in c++ or have different behavior
>>
>>62014026
I'd be surprised if a majority of C libraries didn't choke on malloc when compiled as C++.
>>
>>62014041
malloc does the same thing in c and c++
>>
>>62014063
int *arr = malloc(n * sizeof *arr);

idiomatic C, fails as C++
>>
>>62014063
Yes, but C++ have stricter pointer types and will generate compiler errors for implicit casts.
>>
>>62014083
instead of memeing show me c library that actually writes such code
>>
>>62014154
Most of them? Casting pointers returned by malloc is considered bad practice.
>>
>>62014210
more like none of them, i use few c libs and they all compile
>>
>>62014210
>Casting pointers returned by malloc is considered bad practice.
but why
>>
>>62014224
Because a) they use
extern C
and b) the header you're usually including from C++ contains mostly just declarations.

>>62014248
Casting suppresses potential bad assignments. You accidentally assign some other variable than the void pointer but since there's a cast, the compiler assumes everything is in order.
>>
>>62014224
>i use few c libs and they all compile
They compile as C, is my guess.
>>
>>62014296
>Casting suppresses potential bad assignments
Meant
>casting suppresses potential errors/warnings that the compiler would otherwise report in case of bad assignment.
>>
>>62014296
extern C doesn't make implicit void* conversions work m8
>>
Does C++ have a use in the security industry? Or is it all C/ASM/Python
>>
File: 1453713807800.jpg (12KB, 220x281px) Image search: [Google]
1453713807800.jpg
12KB, 220x281px
>>62014313
yeah, but i compile lua myself in c++ and there was only 1 error
>>
>>62014325
His point is that the other anon probably isn't actually compiling his C libraries, but rather linking against it.
>>
>>62007532
Because I want to participate in obfuscated/underhanded C contests
>>
>>62009563
I honestly thought that was Java's issue, not C
>>
>>62013761
>make an OS
userland sure, kernel? no.
>>
>>62014950
Obviously I mean kernel when I say OS.
Everyone who says OS means the kernel.
You can make a kernel in C++ if you want to, but C is easier.
>>
>>62014967
I would like to interject for a moment...
>>
>>62007580
https://www.joelonsoftware.com/2002/11/11/the-law-of-leaky-abstractions/
>>
>>62013799
auto specifies automatic storage, that is, it gets destroyed automatically when the scope wherein it resides is destroyed
>>
>>62009567
So what, only assembly and opcodes are low level? Is BASIC? Have you ever actually used any?
>>
>>62007532
C++ is filled with unnecessary features and STL is a tremendous pain in the ass to use. People can claim that C++ is easier and less prone to errors all they like but that isn't going to change the fact that C is a much more consistent, less exceptional language.

Some people just prefer the simpler style of C.
>>
>>62007532
I don't have enough confidence in myself to handle such a complex language. There are several, sometimes even tens of ways to do the same thing, and to do it the right way you have to know the advantages and disadvantages of each method and your specific case. This becomes worse with multiple programmers and big projects, which, if not managed without very strict discipline can become an unorganized (methodology-wise) mess that's hard to learn, hard to maintain and hard to expand.

With C, there are much fewer ways to do the same thing. And when there are, they're easy to understand.
I prefer to put my efforts into the implementation of the program, not into the full utilisation of the language.

If there was a non-meme (with an ISO standard) language designed with the same goal C++ was (abstractions without cost) that didn't have to carry decades of legacy compatibility, I would gladly switch. Sadly, so far there is none. Maybe D, Go, Rust or some other, currently meme-tier language will some-day get a certified ISO standard, but currently they're meme-languages.
>>
File: the reason.png (4KB, 35x210px) Image search: [Google]
the reason.png
4KB, 35x210px
>>62007532
pic related
>>
>>62007532
A better question is which standard library is best? I like musl myself.
>>
>>62018053
what will I ever do without [shit that g++ and clang++ support anyway]
>>
>>62017956
this desu
>>
>>62017956
Having an ISO standard doesn't magically make something good. It is entirely possible to write a good standard/specification without dealing with bureaucracy.
Tim Berners-Lee wrote HTML and HTTP all by himself, originally.
>>
Because what C++ added is not only bloat, it's counter-productive.

What should supercede C is something that cleans up what C is great at while not fucking over that core with the added features. D comes to mind.
>>
>>62019706
C++ doesn't come with a GC that nobody asked for.

I like the UFCS and templates though.
>>
>>62014950
You can make a kernel in C++ just fine.

>>62014967
>but C is easier.
No, it's the exact same difficulty in C++ if you want to.
>>
>>62007542
>wahhhhh I want modules
>wahhhhhh everyone uses C API but I want modules!!!!
>wahhhhhh they offer a better interface for strings but I want a single thing to learn
Brainlets OUT
>>
>>62007683

The success of C++ is it allows many more boundary conditions and code reuse that enable groups of programmers to not really work together, but make a finished product. With C, the programmers would need to work more closely together, which the high rate of autism in computer science circles somewhat limits.

Everything would run faster, leaner, and be easier to modify if it were written in C instead of C++, but in the real world coders come and go and have difficulty communicating with one another, so the scope boundaries that C++ enables make C++ more successful for bigger software projects in a business environment.
>>
>>62021116
So it's a shitty language, but a good corporate product?
>>
>>62007532
Wait I thought C++ compilers support any C code so shouldn't the C++ circle include the left bit sticking out in the image as well?
>>
>>62009251
Actually, most of the openssl implementation is platform-specific assembly for speeds sake.
>>
>>62007532
obligatory
http://harmful.cat-v.org/software/c++/linus
>>
>>62007532
why even use c++ when rust is out
>>
>>62007542
Sounds like D is the language for you pham.
>>
>>62007532
>C is a subset of C++
pic related lel
>>
>>62021200
There are a few edge cases of things that work in C but don't work in C++.
Many of them are supported as compiler-specific extensions.
>>
>>62010106
If you remove immutability and borrowk from Rust that's not Rust anymore... that's C
>>
Can someone red pill me on Rust? Why should I care about it?
>>
>>62021713
You're genuinely retarded if you think that.
>What are traits
>What is pattern matching
>What are generics
etc

Rust without the borrow checker / immutability by default is NOTHING like C, not even the syntax is close. It wouldn't even be a BIT like C, not ONE BIT.
If anything, removing those things from Rust would move it closer to C++, but still making it better than C++.
Traits and pattern matching is Rusts most important feature. Not the borrow checker or the immutability by default, those are just safety bullshit for people who can't program properly or come up with good designs.

Protip: Having good abstractions naturally increases safety.
The borrow checker was a mistake that is too coarse and rejects too many perfectly correct programs.

>>62022027
Wait until they improve the borrow checker so that it isn't so coarse. I remember they have plans for that by using non-lexical lifetimes or something, not sure what the progress on that is.
I also hope they fix the ugly mut syntax.
>
&mut i32

>
mut & mut i32

Disgusting,
>>
test.cpp: In function 'void print(const StringToStringMap&)':
test.cpp:8: error: conversion from
'std::_Rb_tree_const_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >' to non-scalar type
'std::_Rb_tree_iterator<std::pair<const std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > > >' requested
>>
>>62007532
If you learn either and aren't able to write code in the other you're doing something wrong.
Thread posts: 145
Thread images: 8


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