C is the perfect programming language and will generate optimal bina-

C is the perfect programming language and will generate optimal bina-

Attached: c btfo.png (1920x857, 76K)

Other urls found in this thread:

pubs.opengroup.org/onlinepubs/9699919799/utilities/m4.html
twitter.com/NSFWRedditImage

Is the only example you can use an unrealistic one? these type of functions in real programs are called at runtime, in which case the c and c++ version would be identifical

>computation done on static data
>unrealistic
Seethe.

Nice try.

>constexpr vs non-constant function
lol

It's the exact same side code, dumdums

Congratulations, you managed to be even more retarded than R*st shills.

no it's not retard.

go back 2 skool

Post the code, numbnut. I am not typing all that shit.

lmao why would he make it easy for you to prove him wrong?

not OP but
#include
#include

static inline const bool is_prime(const uint64_t p){
for(uint64_t k = 2; k * k

>[\code]
you fucked it up retard

Piss off nerd

are you also a ghoul in real life?

code

[/code]
#include
#include

static inline const bool is_prime(const uint64_t p){
for(uint64_t k = 2; k * k

const doesnt change shit

Attached: Screenshot_2019-08-31 Compiler Explorer.png (1866x878, 117K)

learn how C works retard. const doesn't mean the same thing as C++'s constexpr

less code = good
more code = bad

I have tried everything, C loses this time.

assemblylet here

In the assembly generated for the C example, does the execution "fall through" the main function and into .L2? or does execution end as soon as it reaches .L2?

It goes from top to bottom. You can change the control flow by using the jump instructions.

Rust doesn't have this problem.

Attached: no u.png (1916x868, 118K)

>writes two programs with different semantics
>they generate different binaries

Attached: jogged nog.gif (300x300, 486K)

Go ahead, show me your C constexprs!

>didnt' use const fn
Once constant functions support loops, rust will be able to generate identical code to C++ here

behold, the perfect compiler

Attached: msvc.png (1510x2216, 400K)

remove the const from the function declaration. it doesn't do anything. You are trying to specify that the return type is a const ui8, but that doesn't mean anything because the ui8 is just an integer being copied around. It only means something for return types that are pointers, e.g. const char* says that the function returns a pointer to a constant string.

Name one non-brainlet who claimed that it was ever perfect?

Here, I made your code readable.

Attached: iters.png (1920x910, 88K)

despise autists who about assembly level optimization instead algorithmic complexity

Is there a static analyzer that will tell me when I'm not using the latest C++ standard for something?
I think the only issues I have with C++ is not knowing when I'm writing "old C++" since it's just decades of extensions on extensions. The standard revisions of C itself seem much less in multiple ways, like the amount of changes and the complexity of those changes, compared to C++ revisions.

Attached: medusa.gif (130x200, 10K)

Wait no I'm retarded, I can't read code.

Attached: iters.png (1920x910, 88K)

Why isn't constexpr the default? Shouldn't the same optimization be possible without constexpr in this case, maybe with like -O2, based on the compiler knowing if the function is called with a literal and if the function body meets the compile evaluation requirements?

>replacing O(sqrt(2)^n) with O(1)
>hurg durp microoptimization r evul

int main(void){
return 454396537;
}

more like unreadable
what the fuck is this retarded shit

But that's true, you fucking retard.

summerfags gtfo

>Cnile can't cope with a little abstraction

Attached: 1527854576170.png (1074x856, 558K)

Can you nest code blocks on 4channel?

abc

funny, because that code doesn't even work.

>decide to go high level
>foo.bar is bar(foo()) instead of foo(bar))

That's absolutely niggerlicious.

Attached: 1562274008786.jpg (1469x1102, 320K)

No but you can nest nests.

Attached: nesting nests.jpg (800x1052, 142K)

I already fixed it, pic related. Writing code at 1am is never a good idea.

>Cnile can't comprehend what high-level is supposed to look like, and is even proud of this fact
How cute.

Attached: iterator_primes.png (460x401, 12K)

>Cnile can't comprehend what high-level is supposed to look like, and is even proud of this fact

You wish. I eat monads in the breakfast. Don't ever quote me again, you trannigeger.

>I eat monads in the breakfast.
>you trannigeger
Lmao, and I thought I was sleep deprived.

why can't we standardize on rust? everyone, and i really do mean everyone outside of cancerous imageboards agree that C is an outdated language along with C++. most people like rust, and those who dont like go. the discussion should end at that, let retarded Jow Forums users use gimmicky languages that nobody uses (e.g. nim)

I slept for about 20 hours, I decided to correct the average.

user sleeps so that we may all stay awake.
You're doing God's work.

>why can't we standardize on rust?
I imagine a lot of people who work with C/C++ do so for one of several reasons
>C (sometimes not even C++) is the only "high" level language available, like with MCU/embedded development
>they already have a C/C++ codebase (drivers, kernels, JVM, CPython, various video game engines, browsers, etc.)
So, that's why. Projects which needed the lower-level access/performance of C/C++ are already written in C/C++ and a lot of them are very large indeed. Embedded development will often use C because its low-level nature is suitable but also easier to work with compared to whatever flavor of ASM is applicable. A lot of new projects which aren't performance-critical will use a language with much more abstraction like JS, Python, Java, C# or something else .NET based and so on.

So where's the practical application of Rust? I guess it would be in large, performance-critical applications, but only those which are starting from scratch and do not already have an extensive C/C++ codebase. That doesn't seem like a niche which will make it popular all that quick.

>C 941 ms
>C++ 4162 ms
Looks like C wins.

>rust
OP is talking about C vs C++ on a feature that C++ has but C lacks (and rust lacks too btw), tell me, how is being retarded.
>cancerous imageboards
Why are you here if you don't like it here? Nobody is forcing you to stay reddit nigger.

That's compilation time retard

this.

Wrong.

Common Lisp is the perfect programming language.

>wanna reply how bad this bait is
>see half of Jow Forums bites it and has no idea what constexpr is

I think it's time I leave this site.

See you tomorrow!

lol

>Is there a static analyzer that will tell me when I'm not using the latest C++ standard for something?
Does it matter? I still code in C++03. Maybe 98 actually, I'm not sure.

Considering the OP, it probably does. Writing in 1 standard versus another will produce different, likely better, output.
Probably not that drastic, but who knows. The more context the compiler has, the better.

Attached: CppCon 2016 - Jason Turner “Rich Code for Tiny Computers - A Simple Commodore 64 Game in C++17”- (1280x720, 1.93M)

this is why new languages like rust make immutable data the default.

Why does C not have the equivalent of constexpr then, huh? Go ahead, try to get C to evaluate this at compile time.

bump

the point is, that's out of the scope of the language, you can use any external tool, macro engine, etc to do that

>ITS OUTSIDE OF THE SCOPE TO MAKE YOUR CODE RUN FASTER
cope

>make your code run faster
no, i mean just calculate your constants with whatever language/tool before compiling

all it takes is putting a god damn script in the source folder that outputs a c header file and make runs it before compiling

>returning non-zero value on main
Maximum retard

Based and redpilled

All the seething Ctards in this thread

are you mad? you seem mad. why are you mad?

I will admit the syntax is much nicer here

that's less readable you dumb codemonkey

I solved it with c retards.

I only used m4 and make, only standard stuff for c development. Took me like half a minute to implement this bloat feature from C++.

Attached: 4chan.png (1908x1012, 141K)

>using such a buttfuck slow algorithm for finding prime numbers

With cleaner asm output before you autists complain

Attached: 4chan.png (1907x1009, 118K)

Lmao C++ btfo.

it's in his interest retard

There are two problems with this ``solution'':
• An extra tool (m4) has been employed which is not part of the standard language toolkit
• Using macros foregoes the type system and it's generally a frowned-upon practice in any serious C development standard, such as MISRA.

All in all, this chap is correct. Things like static analysis, unit testing, code profiling, functional testing, and etc should be an essential part of the development process but not part of the language. I don't expect the teenbros on neo/g/ to understand though.

>Took me like half a minute to implement this bloat feature from C++.
Only took me 1 second to type "constexpr".

Now pass in a runtime value into compute_sum
What's that? It doesn't compile? oh well that's just too bad. I guess C++ wins again.

why not? 1am ur just getting started some nites

>using GCC instead of clang and expecting it to be minimal
lmao

GCC usually generates better code than clang

>``solution''
I see what you did there :p

>An extra tool (m4) has been employed which is not part of the standard language toolkit

good point, although it is part of POSIX
pubs.opengroup.org/onlinepubs/9699919799/utilities/m4.html
(I'm aware C can be built on non POSIX conforming environments, but i doubt it's an expensive requirement, since now windows includes ubuntu as i heard) Just replace esyscmd with syscmd and it's POSIX compilant I suppose.

>Using macros foregoes the type system and it's generally a frowned-upon practice in any serious C development standard, such as MISRA.

i bet it's handled nicer/safer if it's implemented in the compiler based on the standard, but matching the type and the printf format string should give enough safety. Both the printf format and the syntax of constants are defined by the C standard, thus it should be possible to verify whether a format thing guarantees safety for a particular type based on the C standard alone.

You can return literally anything you want, including a null pointer, just to fuck with you codelets who still fear the pointer.

you know I can put the functions in a separate file and link against it from both the main program and the macro

>You can aim a gun literally wherever you want, including at your feet, just to fuck with you gunlets who still fear the bullet.

Which is the greatest compiler of all time ?

I'll just have to make it explicit whether im calling the macro or the actual function. can be done with renaming the macro function to const_compute_sum

Good job, now you're making it harder for the compiler to optimize, and you now have increased complexity.