Quality C/C++ Code

Post things you autisticly practice in your code that helps optimize it and explain why it's better.

I'll start: Using ++i is better than i++
since i++ takes 4-5 steps whereas ++i only takes two and
i++ creates a local value that gets thrown away if your
compiler is too retarded to optimize it

Attached: ansi_chink.jpg (367x499, 26K)

>i++
>++i
Is this bait?

I always initialize everything to zero first, everywhere

0 == i
because you can never do 0 = i

You're glowing in the dark pretty hard right now...

>if your compiler is too retarded to optimize it
If your compiler is too retarded to optimize i++ then you've got bigger problems than microptimizations of your code.

Hi, any recommendation for good textbook to learn C?

My favorite practice is using a different language that isn't horribly outdated, like python. It really cleans up and optimizes my code.

i can be a different type, like a class and ++ can be overloaded. so ++ may use a copy, and that might not be optimized

God i cant fucking tell if that's the letter O or the number 0. Wouldn't you just want to do if(!i)


I completely feel you. I always make sure to do that whenever I use malloc since it picks
fragmented space and doesn't allocate contiguously

>Hi, any recommendation for good textbook to learn C?
O'Reilley Web Assembly

>I'll start: Using ++i is better than i++

Attached: 1535725641743.jpg (550x422, 35K)

lol nice try

do you install it on your arch linux first?

>God i cant fucking tell if that's the letter O or the number 0. Wouldn't you just want to do if(!i)
Install normal fonts
And that was an example, I could write
4 == chan

as well

just as a general rule after every free() i set the pointer to NULL

same

just don't be dumb and type the right thing. i have no idea why all of these preventative measures exist for typing, i'm consistent 99% of the time and would rather not make my code look shittier because i can't type

zoomer detected
>p-p-python is better
you use the best tool for the job, sorry to say but python is slow as molasses. imagine if AAA games were written in python instead of C or C++ lmfao

Attached: 1533744461862.jpg (720x960, 46K)

i dont get it though what does that accomplish

My first integer variable is always int elligent; so that people know I have a very high IQ

Attached: 1535310068904.jpg (720x711, 53K)

I think this makes sense.

int main(void) { volatile int i = 42; i++; ++i; return 0; }

Default optimization for both increments using very old compiler:

movl -8(%ebp), %ecx
addl $1, %ecx
movl %ecx, -8(%ebp)

Increased optimization for both increments using very old compiler:

incl -4(%ebp)

Granted, it helps to use a compiler written in the last 25 years.

>just as a general rule after every free() i set the pointer to NULL

Yeah I do that too as this:
int *ptr = new int[N];

if(!ptr) {
delete ptr;
}

ptr = NULL;

*even though new throws an exception if it doesn't allocate correctly i meant to say

absolutely brainpilled

The worst thing is a lack of comments or documentation. Another evil is constantly changing code style. I'm looking at you rsync.

>that ass
people are paying this nigga thousands of bucks a month for this?
LAME!

You are supposed to be off shift

Attached: 8E614C5B-CBF0-48F3-B29B-ACD2766C08F4.jpg (420x420, 46K)

Isn't using i++ niggerlicious?

Brained and brainpilled

optimization of the increment operator is an issue in c++ not in c

>python
>optimized code

pick one

Attached: zoomer.png (820x331, 191K)

>python
>not horribly outdated
you wut m8

fucking kek

user...

use a modern compiler.
use a modern compiler.
use a modern compiler.

wow addressed those issues so easily.

>using raw pointers in C++
>using NULL in C++ for anything other than interfacing with C crap
friend...

You don't get the point of 0 == i; it is simply that you can not assign to a constant, so it's safer to have the constant on the left in a comparison.

Lul. But my dudes. Explain please.

i get the point you idiot; use a modern compiler. it will warn you when you appear to be assigning in that context.

Well ok, I was thinking that no compiler will give you an error. Warnings are good too but easier to overlook, still a fair point.

>warnings are good but easy to overlook
if you're developing anything remotely seriously, and it's not a case of "write 10,000 lines of code or your daughter gets it", there is no reason for you to be overlooking warnings unless you've discovered a compiler bug or you're intentionally doing something very weird for a very good reason.

>python and optimize in one breath

Attached: 1536319814453.jpg (486x309, 29K)

>t. not a real programmer
some python libraries do things very well, much more quickly than even many experience C programmers could do

I think you're missing the part where c code has to be interpreted into python nigger.

>I think you're missing the part where c code has to be interpreted into python nigger.
can you give me a basic gestalt?

>i++ creates a local value that gets thrown away if your
>compiler is too retarded to optimize it
compilers stopped being this retarded back in the 80s, this is a complete non problem

do you realize that time you wasted writing your post is infinitely bigger than processor time you saved using ++i instead of i++?

i think you're missing the part where none of that interpetation is visible to you and the libraries are much more accessible than any comparable C libraries
>hurr python sucks except for where it doesn't but that isn't "python" according to my arbitrary and convenient definition of "python"

>optimizes my code

If you really apply yourself you can optimize to go from 100x slower than C++ to 50x slower only.

Attached: 1428589704247.png (338x286, 7K)

>pre-ANSI parameter declaration and loop unrolling
I'm so glad #pragma unroll exists these days.

BASED

>the libraries are much more accessible than any comparable C libraries
oh booohoohoo pointers are too hard mommy help me pls

>what are sequence points

There is literally no reason do the choice between prefix and postfix to be dictated by anything other than semantics. If you really do this to save three machine instructions then you're fucking retarded.

Good luck with the second half of K&R Mr leet haxor, don't give up!

*For, not do. Dammit.

i dont use raw pointers usually but if I need to that's what I do idk why I hate nullptr

>C/C++ thread
>Talk about Python

You Python fags are insufferable. Go be a brainlet somewhere else.

That's a great thing to do if you don't know what instruction cache is.

Stop writing C in C++. Your code doesn't even work as intended.

instead of i++ I write i = i+1

based and redpilled

That's retarded and a waste of performance.