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

There is no such thing as perfect co-

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

File: applecode.png (15KB, 364x257px) Image search: [Google]
applecode.png
15KB, 364x257px
There is no such thing as perfect co-
>>
>>60657305
pic not related
>>
File: kode_with_karlie_kloss.jpg (25KB, 1155x350px) Image search: [Google]
kode_with_karlie_kloss.jpg
25KB, 1155x350px
>>60657305
>>
Everything that needs to be said about your code bait has been said in the previous thread.
https://warosu.org/g/thread/59266741
>>
File: 1495850341740.jpg (48KB, 498x456px) Image search: [Google]
1495850341740.jpg
48KB, 498x456px
>>60657305
>Old style function declarations
>>
>>60657324
She even has tests!
>>
File: 1438583010652.png (20KB, 213x334px) Image search: [Google]
1438583010652.png
20KB, 213x334px
>>60657305
There is no such thing as perfect co-
>>
>when you think you're a genius for learning pointer arithmetic
>>
Not a coder, is this how the code works?
strlen accepts a string and returns its length, presumably. There's a const declaration that I have no idea what it does, then a register declaration which again I have no idea what it does. Then a for loop that does increments s which starts as a pointer to the start of the string, and as long as its content is not the end-of-string char, increments the address by 1.
Then it returns the difference between the incremented address and the string address, which is the string length.

The readability of this code is very low. One-liners are fun, but code needs to be read and edited conveniently. Besides, writing out that for loop in a more readable way doesn't make it any slower when compiled; the compiler doesn't care if code is written out in one line or several if it does exactly the same thing, from an assembly code point of view.
>>
>>60657305
>2017
>not using C++17 constexprs
>>
>>60657404
>There's a const declaration that I have no idea what it does,
Guarantees that the pointee isn't modified

>then a register declaration which again I have no idea what it does
It's a compiler hint. It basically says "I'm going to use this variable A LOT, you should probably use a register for it rather than a memory location"

> Then a for loop that does increments s which starts as a pointer to the start of the string, and as long as its content is not the end-of-string char, increments the address by 1.
Correct

>Then it returns the difference between the incremented address and the string address, which is the string length.
Correct

>The readability of this code is very low
It is very good, you're just not experienced with C
>>
>>60657404
Yes, you've basically got it correct.
>const declaration
It's saying that it won't be modified.
>register declaration
It's an optimisation feature. Just ignore it, it doesn't really make any difference for this code.
>The readability of this code is very low
An experienced C programmer would be very well versed with pointers, and would not see that code as "tricky".
>>
I don't know much about C. Here's what I don't understand:
If s is declared as const, it means it can't be changed, right? How can you then do s = str or ++s? What's the purpose of it being const then?
>>
>>60657603
The pointed to value is const, not the pointer itself.
const char *ptr = whatever;
ptr += 1; // This is fine
*ptr += 1; // This isn't
>>
>>60657603
The data/pointee is unmodifiable, not the pointer itself.

char const *s; // can modify pointer, cannot modify pointee
const char *s; // alternative form of the above
char * const s; // cannot modify pointer, can modify pointee
char const * const s; // cannot modify neither pointer nor pointee
>>
>>60657603
s++ good
*s++ bad
>>
File: vomit.png (88KB, 389x213px) Image search: [Google]
vomit.png
88KB, 389x213px
>>60657305

> declaring the parameter outside of the parameter list
>>
>>60657635
>>60657638
>>60657651
Ok I see now thank you. So it's declared as const to make sure the chars aren't modified while the pointer is moving across the string. Is that correct? If so, why doesn't the const declaration of str already provide that?
>>
>>60657742
>So it's declared as const to make sure the chars aren't modified while the pointer is moving across the string. Is that correct
Yes

>If so, why doesn't the const declaration of str already provide that?
Failing to declare s as a similar pointer type as str and then attempting to assign str to s is undefined behaviour and will most likely result in a compiler warning or error.
>>
>>60657742
>So it's declared as const to make sure the chars aren't modified while the pointer is moving across the string. Is that correct?
Yes.
>why doesn't the const declaration of str already provide that?
It does. It's just that you can't 'discard' a type qualifier (e.g. const) by assigning it to another variable, so you need to specify it on each variable.
const char *str = whatever;
char *s = str; // Compiler will complain
>>
>>60657759
>>60657778
Ok that makes sense. Thanks for the explanation.
>>
File: g.jpg (62KB, 660x596px) Image search: [Google]
g.jpg
62KB, 660x596px
>>60657324
>>
>>60657406
>C++
>being able to force a compiler to inline
>the compiler having an option to refuse
>being able to force inlining when the compiler refuses
How deep does the hole go?
>>
>>60657870
lol'd
>>
>>60657305
You have to go back pajeet
>>
File: 1494360806154.png (115KB, 208x206px) Image search: [Google]
1494360806154.png
115KB, 208x206px
>>60657404
>coder
>>
File: clueless.jpg (13KB, 240x240px) Image search: [Google]
clueless.jpg
13KB, 240x240px
>>60657857
You left out a crucial part of the original meme.
>>
>>60657382
kys degenerate
>>
>>60657404
>but code needs to be read and edited conveniently
You're expected to know your shit when you do C development, if pointer arithmetic is too hard for you, you HAVE to spend time learning it or fuck off to webdev.
We already have too much buffer overflow problems made by careless developers to deal with more incompetent developers.
>>
>>60657382
I recognize that co-!
Thread posts: 30
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.