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

/dpt/ - Daily Programming Thread

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: 368
Thread images: 45

File: unironical_code.png (288KB, 1790x1071px) Image search: [Google]
unironical_code.png
288KB, 1790x1071px
What are you working on, /g/?

Previous thread: >>61716012
>>
File: 1374575621331.jpg (53KB, 1280x720px) Image search: [Google]
1374575621331.jpg
53KB, 1280x720px
Please post an anime image next time.
>>
Nothing. Give me a project. Preferably one that involves hardware because all this shit webdev at my job is killing me.
>>
>>61722392
thats the face u'll be making when im in ur sissy ass
>>
File: OOPfag.jpg (26KB, 400x400px) Image search: [Google]
OOPfag.jpg
26KB, 400x400px
>>61722392
he did tho
>>
File: bingo.png (301KB, 1279x723px) Image search: [Google]
bingo.png
301KB, 1279x723px
>>61722392
>>
File: coolface.jpg (110KB, 762x1042px) Image search: [Google]
coolface.jpg
110KB, 762x1042px
>>61722392
>implying that is not animu
>>
>>61722412
The hero /dpt/ deserves.
>>
>>61722392
Wearing a hijab!
>>
>>61722378
Holy shit this code is so disgusting.
>>
>>61722435
No wonder GNU shit is so buggy.
>>
>>61722435
>>61722440
It's clearly an optimisation.
>>
>>61722367
Main goals are:
>computer blocks and automaton mobs programmable (eval yes!)
>multiplayer (kinda mandatory for this sort of thing but also I haven't done network programming since I was 11 so it should be fun)
>dynamically loading mods from ~/.game directory (really easy with (load))
>>
>>61722470
We know it, it's called loop unrolling. It's still idiotic, because the sheer extra binary size will vitiate it. Not to mention unnecessarily long code is error prone and hard to maintain, and it looks like it was written by a pajeet.
>>
>>61722517
>because the sheer extra binary size will vitiate it
Do you honestly think they don't profile and test the shit out of these sorts of things? God, you're so fucking stupid.
Also, standard libraries are known for all sorts of crazy tricks to push speed as much as possible. It benefits not only them, but every other C program.
>hard to maintain
The specification of strlen isn't going to fucking change. It's standard.
"maintainability" is unimportant here, and takes a backseat to performance.
You can't treat standard library code like you do other code.
>error prone
Please show how that particular function is buggy.
>>
>>61722517
The sheer extra binary size from 20 extra instructions? Who cares if it looks like it was written by a pajeet? It's fast and libc should be fast.

glibc strlen is about a hundred times faster than a naive implementation. No joke. It's that much faster than the "pretty" solution.

Naive:
int shittystrlen(char * c) {
char * cursor = c;
while(*(++cursor) != 0);
return cursor - c;
}

real    0m51.536s
user 0m51.500s
sys 0m0.008s

glibc:
Horribly awful

real    0m0.378s
user 0m0.376s
sys 0m0.000s


And the code to test it:
#include <stdio.h>
#include <string.h>
char * benis = "fill this up with a longer string";
void main() {
int i;
for(int j = 0; j < 10000000; j++)
i = strlen(benis);
printf("%i\n",i);
}
>>
>>61722593
>136 times faster
noice
>>
First for /agdg/ plz go and stay go
>>
File: assdrive.jpg (102KB, 610x814px) Image search: [Google]
assdrive.jpg
102KB, 610x814px
>>61721332
>>61721704
Anyone here experienced in Android development?

I'm still dumbfounded by this, probably something trivial I'm not realizing. But idk if it's a peculiarity with the android studio IDE itself or just a rule of Java that I've forgotten.
>>
>>61722684
Feel free to post and discuss other programs!
>>
I hear people saying Rust will fail, but it seems to start getting a lot of adoption. Tell me how is Rust going to fail when it is already starting to become very popular.
>>
File: asdf.png (12KB, 645x463px) Image search: [Google]
asdf.png
12KB, 645x463px
Can anyone help me, I dont understand why this isnt working:

threads[prevIndex] -> nextThread = threads[currentIndex] -> nextThread

Im trying to achieve pic related.

"threads" is an array of pointers pointing to "thread" structs, where each thread struct contains a struct thread *nextThread; member.

How the fuck do I make a previous thread point to the thread of the current threads pointer to the next thread? (effectively taking out a node in the linked thread list)

Tried so much shit its getting frustrating
>>
>>61722593
>String literal
Compiler optimisations are surely fucking with that.
Anyway, here is a more fair benchmark:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

__attribute__((noinline))
size_t glibc_strlen(const char *str)
{
// Omitted so this will fit in a single post, but it's taken from the latest glibc.
// Also, we don't use strlen directly, because the compiler notices it as a special function,
// and will omit different code.
}

__attribute__((noinline))
size_t naive_strlen(const char *str)
{
register size_t len = 0;
for (; *str; ++str)
++len;

return len;
}

int main(int argc, char *argv[])
{
if (argc != 2)
return 1;

clock_t start, end;
size_t len;

start = clock();
len = glibc_strlen(argv[1]);
end = clock();

printf("%zu: glibc_strlen took %f seconds\n", len, (float)(end - start) / CLOCKS_PER_SEC);

start = clock();
len = naive_strlen(argv[1]);
end = clock();

printf("%zu: naive_strlen took %f seconds\n", len, (float)(end - start) / CLOCKS_PER_SEC);
}

$ gcc test.c -O3
$ ./a.out "$(printf '%100000s')"
100000: glibc_strlen took 0.000036 seconds
100000: naive_strlen took 0.000147 seconds
>>
>>61722725
Personally, I don't think Rust will fail, but I don't see it actually replacing C/C++ for larger programs, simply because of the inertia of the languages and tools for those languages.
>>
>>61722720
When it comes to algorithms like Djikstra's, concerning the 'edges' that each node is connected to, would you implement these as just a list of nodes that the node is connected to?

So, something like a linked list of nodes inside of each node for every node they're connected to?
>>
File: anime-man.jpg (24KB, 400x400px) Image search: [Google]
anime-man.jpg
24KB, 400x400px
>>61722392
>>
>>61722348
>Actually I feel like I'd committing an injustice against myself by releasing it for free
Release it under GPL and without the assets needed to play it, kind of like how the idTech engines have been released. I want to see this too.
>>
>>61722738
Rust is nearly unheard of in the industries it is trying to take on. It might catch on for high performance applications, but I don't see it actually doing much in the systems world other than the occasional 30 year-old unix rewrite, now with terminal colors.
>>
>>61722763
>anime
this is clearly a manga picture
>>
>>61722378
I'm unable to learn OpenGL, I have the recommended book. What even is this shit fuggggg
>>
>>61722785
>high performance applications
C is still the undisputed king in that arena.
>>
>>61722785
I think unheard of is a bit of a stretch, but I agree that I don't really replacing anything.

>>61722815
Rust has inline assembly too.
>>
>>61722825
>Rust has inline assembly too.
So? That's not what makes a language fast.
>>
File: 1413262323597.png (407KB, 570x578px) Image search: [Google]
1413262323597.png
407KB, 570x578px
ground up neural net using sensory input for an embedded system.
>completely in C
>>
>>61722825
When and if Rust becomes an industry standard is the day I should retire.
>>
File: 1494485129107.gif (575KB, 500x375px) Image search: [Google]
1494485129107.gif
575KB, 500x375px
>>61722392
made a simple script that parses a user's pastebin for hentai games.

the real beauty lies in how it's organized.

uses jdownloader API to group the download links in the same package as the dlsite images, so now I can have a nice folder name, with proper images and the game in a folder

the best part?
only took 1 hour(and that was only because the jdownloader python api was undocumented and it took me forever to install pycrypto, a dependency of the api.
>>
>>61722732
If threads is of type thread_t* and not thread_t** threads[i] returns the thread itself.

threads[previous].next = threads[current].next;


or

(threads + previous)->next = (threads + current)->next;


This is what I'm guessing since you didn't give any compiler error or weird behaviour.
>>
>>61722815
It is, but the minimal losses you get with C++ is well worth the gains in the application world, as countless applications proved and continue to prove. Rust stands a chance here I feel, one because it's exactly Mozilla's wheelhouse, and two, it's a great area for disruption. Systems I'm still not sure how much of it can be disrupted, even if rust gains prominence among the community.
>>
>>61722735
Hmm neat. That does make a little more sense. I was astonished with my results.

I didn't turn any optimization on though. I was worried about gcc optimizing away the loop i used to make glibc strlen take a noticeable amount of time. Dubious about compiler emitting different code

glibc:
main:
.LFB1:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp
.cfi_def_cfa_register 6
sub rsp, 16
mov DWORD PTR -8[rbp], 0
jmp .L5
.L6:
mov rax, QWORD PTR benis[rip]
mov rdi, rax
call strlen@PLT
mov DWORD PTR -4[rbp], eax
add DWORD PTR -8[rbp], 1
.L5:
cmp DWORD PTR -8[rbp], 9999999
jle .L6
mov eax, DWORD PTR -4[rbp]
mov esi, eax
lea rdi, .LC1[rip]
mov eax, 0
call printf@PLT
nop
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc

And shittystrlen:
main:
.LFB1:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp
.cfi_def_cfa_register 6
sub rsp, 16
mov DWORD PTR -8[rbp], 0
jmp .L5
.L6:
mov rax, QWORD PTR benis[rip]
mov rdi, rax
call shittystrlen
mov DWORD PTR -4[rbp], eax
add DWORD PTR -8[rbp], 1
.L5:
cmp DWORD PTR -8[rbp], 9999999
jle .L6
mov eax, DWORD PTR -4[rbp]
mov esi, eax
lea rdi, .LC1[rip]
mov eax, 0
call printf@PLT
nop
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc


Unless I'm missing something those look pretty identical.

As for why your code is 10 times faster than mine, I'm not sure desu. I doubt compiling in O5 would cause it. Found out that 4chan has a line cap too (fucking assembly) so can't post the full source for that but it looks pretty normal.
.L2:
add QWORD PTR -8[rbp], 1
mov rax, QWORD PTR -8[rbp]
movzx eax, BYTE PTR [rax]
test al, al

Both pointers are only in register, and I see nothing weird about it loading chars.
>>
>>61722808
Having trouble with something anon?
>>
File: glibc.png (2KB, 532x215px) Image search: [Google]
glibc.png
2KB, 532x215px
>>61722551
>Do you honestly think they don't profile and test the shit out of these sorts of things?
I don't think so. Not with the fame their software has. Do you really trust them so blindly?

>God, you're so fucking stupid.
No, you are just an obvious GNU zealot.

>standard libraries are known for all sorts of crazy tricks
I could pull up BSD's strlen, musl's strlen, Apple's strlen, and none of them are over 7 lines of code (counting empty lines). Compare it yourself!

>The specification of strlen isn't going to fucking change.
Maybe not, but have you ever heard of regressions?

>Please show how that particular function is buggy.
That one probably isn't, but the point here is bigger than only that function in particular, it's about good coding practices in general. And if this is standard GNU practice for all their code (and it must be), then it explains at least in part why their code is disproportionately buggier. glibc in particular's been known for having some pretty nasty bugs (pic related).

Reminder that your functions should fit in one 80x24 terminal screen.

>>61722593
>The sheer extra binary size from 20 extra instructions?
20 extra instructions here, 20 extra instructions there...

Again, like the poster above you, your vision is too narrow. All those extra instructions add up to glibc being the most bloated implementation of the standard C library out there. Compare it yourself!

>glibc strlen is about a hundred times faster than a naive implementation
It isn't. I'm gonna refute your little experiment in a following post, but first, let me say that, even if it was faster by a constant, anyone who knows the basics about algorithms knows that's meaningless asymptotically.
>>
>>61722593
>your little experiment
For starters, it shows how little you understand about how libraries are loaded and how compilers work.

1st mistake: you used the linked strlen instead of copying and pasting the code from it in your function. That makes a huge difference.

2nd mistake: you didn't take into account compiler optimizations (the compiler knows when you're using the standard lib).

3rd mistake: you missed the point. The criticism is towards a particular section of the implementation, namely lines 84 through 102. Those can be replaced by a simple loop and return statement, and I guarantee you the difference will be in the order of milliseconds.

  for (i=0; (i<sizeof(longword)) && (cp[i] != 0); ++i);
return cp - str + i;
>>
>>61722808
Really? I found opengl superbible super good to learn opengl.
>>
>>61722815
Daily reminder that Java is as fast as C these days.
>>
>>61722808
Try https://learnopengl.com
>>
File: FreeBSD-strlen.png (101KB, 575x725px) Image search: [Google]
FreeBSD-strlen.png
101KB, 575x725px
>>61722517
FreeBSD libc also does it through a preprocessor function. No, it's not idiotic by concept, but GNU's coding style is. Pic related, where testbyte() is defined below.

#define testbyte(x)                \
do { \
if (p[x] == '\0') \
return (p - str + x); \
} while (0)


The reason stated is that branching is more expensive on modern systems than raw conditions, and this type of optimization is very important in a libc that's used as the foundation for every userspace program on the system, so this function is expected to run many, many times every second.
>>
File: 2.png (65KB, 830x548px) Image search: [Google]
2.png
65KB, 830x548px
>>61722856
Sorry im so lost right now spent so long trying to figure this out so nothings really making sense to me anymore, pic related, what do I do?
>>
>>61722831
When you absolutely need the highest possible performance, you inline assembly.
>>
>>61722924
>Java
I don't care how fast Java becomes, you couldn't pay me 6 figures to deal with that shit.
>>
>>61722907
OOh lists you're a big boy. I looked at the source code because I know about compiler optimizaitons and stdlib.

They look identical minus the function call. Or does the optimization happen in the linker now?

(1) it's nanoseconds faster not miliseconds faster. (2) I missed zero points because optimizations add up. I don't care if you think it's ugly. No one except you does. Nanoseconds add up. A single nanosecond here and a single there make a difference for the standard library.
>>
>>61722908
>tfw purchased the other one
There were 2 books, I didn't purchase the SuperBible. I can kind of program in it but I'm not sure what I'm doing, going to keep reading it and then read up on stuff I don't know afterwards. Right now it feels like I'm not making any progress though.
>>
>>61722924
That is flat out wrong.
>>
>>61722907
>in the order of milliseconds
That's actually quite a lot.
>>
>>61722940
What's so bad about Java? What can be better done in C? Honest question I want to know.
>>
>>61722963
Write a function in java that takes two ints and swaps them.
>>
>>61722946
Oh the orange book is more of a reference manual to my understanding. Never read it though.
>>
>>61722907
See >>61722735
>>
File: aya.png (783KB, 1280x720px) Image search: [Google]
aya.png
783KB, 1280x720px
>>61722825
>>61722815
>>61722831
I think zero cost abstraction is such a meme. There is almost always cost when you abstract something because you are generalizing a problem. Compare these two programs fizzbuzz programs.

// rust_fizzbuzz.rs
fn main() {
for i in 1..101 {
match (i % 3, i % 5) {
(0, 0) => println!("Fizzbuzz"),
(0, _) => println!("Fizz"),
(_, 0) => println!("Buzz"),
(_, _) => println!("{}", i)
}
}
}

/* c_fizzbuzz.c */
#include <stdio.h>

int main(int argc, char *argv[])
{
int i;
for (i = 1; i <= 100; i++) {
if (i % 5 == 0 && i % 3 == 0)
printf("Fizzbuzz\n");
else if (i % 3 == 0)
printf("Fizz\n");
else if (i % 5 == 0)
printf("Buzz\n");
else
printf("%d\n", i);
}
return 0;
}


I compiled them both with max optimizations in rustc and clang. The assembly output.

$ wc -l rust_fizzbuzz.s
206 rust_fizzbuzz.s

$ wc -l c_fizzbuzz.s
98 fizzbuzz.s


You can clear see that Rust has more than twice the instructions. You can reason that there is twice the amount of comparisons required because Rust has to compare the tuples which is almost twice the amount of comparisons, which is a lot considering it is a simple abstraction.
>>
>>61722963
>What's so bad about Java
I, personally, dislike its syntax, and I dislike being forced to only deal with OOP.
>>
>>61722983
>being forced to only deal with OOP
Java doesn't force you to deal with OOP. You can write 100% procedural code with it. And a big part of the JCL is actually procedural.
>>
>>61722946
The blue and red books? I remember those from school, I'm surprised they're still using them, shaders were still considered novel when I did my graphics programming course work.

Make sure you understand what's actually going on in the opengl pipeline.
>>
File: spamnosp.png (31KB, 735x186px) Image search: [Google]
spamnosp.png
31KB, 735x186px
did the authors fuck up the order of the arguments?

if L(y,y) is 0, that is a good thing because there is no loss.

If L(y=spam, Å·=nospam) = 1 then you are classifying no spam as spam.

If L(y=nospam, Å·=spam) = 10 then you are classifying spam as nospam.

but the second is worse than the first because it has a higher loss, yet they say the first (NS->S) is 10x worse than the second (S->NS)

what?
>>
>>61722982
Have you compared the same version in Rust but with the if statements?
>>
>>61722969
Wh-what's the point in doing that anon?
>>
>>61722982
The whole point of allowing for inline assembly is for you to maximize efficiency in areas that need it, if you need to fizz buzz as fast as possible, then you would write the slow parts in assembly.
>>
>>61722993
oh wait shit I get it now. The actual value is spam but you are classifying it as nospam in the first case.

Making dumb posts is a great way to answer your own questions.
>>
>>61722988
>You can write 100% procedural code
What? Do you mean just lopping all your functions inside of one giant class?
>>
>>61722963
Quite literally everything can be done better in C, if you have the time to do it. This is just by design. One language compiles one step above bare metal, and the other is an intermediary language translated on the fly by a VM.
>>
>>61722993
>>61723007
What book?
>>
>>61722973
>Programming guide
>thought guide meant tutorial
I'm retarded. Also the preview of both books is basically the same thing, I thought they were basically the same books. I already spent my money on the book and I don't have enough shekels to buy another 50$+ book fuuuuggggggg why am I retarded
>>
>>61723011
You don't have to do that. But you can write all functions as static and make all classes methodless with public fields.
>>
>>61722378
>all GNU code follows this retarded style
Suddenly I understand why GTK development never gets anywhere, why GIMP development never gets anywhere, why GNOME development never gets anywhere, etc. etc. etc....
>>
File: 0133001989.jpg (127KB, 481x648px) Image search: [Google]
0133001989.jpg
127KB, 481x648px
>>61723020
p.711
>>
>>61723021
Just return it anon.

That's why returns exist. Say "The description was vague about what it was. This is a reference manual."
>>
Reposting here
If I care about data transfer speed between a windows service and a GUI which IPC method should I use?
So far I have looked at:
WCF
Named Pipes
Shared Memory
>>
>>61723011
>code separation is OOP
>>61722988
>80% of what people call """OOP""" isn't procedural anyway
>>
>>61722989
Do I need to understand anything deeper than what each stage does? I know what they do but how in-depth should I know them?
>>
>>61722995
>>61723002
That wasn't really the point of my argument. The point of my argument was that zero cost abstractions is a meme because there is always a cost to generalize a problem from a specific solution. But, if you must

// rust_fizzbuzz.rs
fn main() {
for i in 1..101 {
if i % 5 == 0 && i % 3 == 0 {
println!("Fizzbuzz");
}
else if i % 3 == 0 {
println!("Fizz");
}
else if i % 5 == 0 {
println!("Buzz");
}
else {
println!("{}", i);
}
}
}


$ wc -l rust_fizzbuzz.s
211 rust_fizzbuzz.s


I get more lines of instructions which is weird. Rust compiler is not mature I guess?
>>
>>61722963
I think it's generally disliked for it's shitty syntax and shitty performance. Combined with it's ubiquitous use in enterprise software (ensuring it's made by codemonkeys), it has quite a bad reputation.
>>
>>61722934
no worries. You should take a break until you feel better though.

So threads is struct thread**? Can you show me the declaration of threads? I don't understand why you did modulus NUMTHREADS either.

If threads is a struct thread* you'll want to do this, keeping out the modulus NUMTHREADS that I don't understand:
(threads + (currentThread - 1))->next = (threads + currentThread)->next;
(threads + (currentThread + 1))->prev = (threads + currentThread)->prev;


if it's a struct thread** the solution you had earlier would've worked.
>>
>>61723024
Don't you have to make your variables inside those functions also static?

Isn't that just going to end up having ridiculous heap allocations?
>>
>>61723030
This is the most pathetic post, as if it's somehow impossible to have a script or macro to reformat code to whatever style wanted/needed for whatever purpose.
>>
>>61723046
I don't really understand what you're struggling with. Is it the actual openGL pipeline and commands you need to call to make something happen? Or is it the underlying theory of 3D computer graphics?
>>
>>61723048
>that really wasn't my point
Yes it was.
Look at the pattern matching vs the if statement verisons.
As you can see, the difference is only 5.

You can't just say "here's C code using C libraries" "here's Rust code using Rust libraries and pattern matching"
"clearly pattern matching is at fault"
>>
>>61723030
Those never get anywhere because there's no money in them and it's not interesting. Companies don't fund gimp because it's worthless compared to adobe.

The only open source projects that get anywhere are ones interesting for programmers. Programmers, especially linux ones, don't care about UX and image editing when they do everything in a command line.
>all GNU code follows this retarded style
It's a pretty typical unrolled loop. You don't like optimizing code? Optimization is addictive desu. Very fun to get the execution time lower and lower and lower. What's wrong with its style?
>>
>>61722907
>in the order of milliseconds.
>insignificant
I too, know nothing about scientifiy computing
>>
>>61723030
>tfw still no file picker thumbnails
>>
I'm in the planning stages on a program I want to write for work. I want to run a batch file of sorts to scan all the IP's on my network, see which ones are being used, gather information about the computer, and gather that information on a list. The ip list my boss and coordinator made is no longer accurate since they seem to forget to change it when they got new computers and such.
>>
>>61723078
Then why the fuck does Rust use twice as many instructions as C? Zero cost abstractions my ass.
>>
>>61723091
Just look at your router's DHCP/ARP log.
>>
>>61723082
>doing scientific computing
>not using FORTRAN
You're asking for all the bad things that happen to you.
>>
>>61723048
Are you sure you aren't just comparing static vs dynamic linking? Rust links statically by default, unlike clang
>>
>>61723048
The point of your argument was only partially related to the specific topic at hand.
If you don't want abstractions, you're free to do away with them for the highest performance possible.
If you think some abstractions are a meme, do away with them.
>>
>>61722412
WHAT DID YOU SAY ABOUT MY YEGOR
>>
>>61723107
How do you static link Rust then?
>>
>>61723100
Reread what I just said

You just saw pattern matching vs if in Rust.
The difference was only 5.
It's not the pattern matching that makes it twice as slow as C.

It's probably the libraries, or maybe a fundamental limitation of C.
>>
>>61723055
I don't remember you having to declare stack variables static in main so I don't think so. But it's been 5 years since I've touched java.

It wouldn't make sense for you to have to do that because static fields and static variables are conceptually distinct.
>>
>>61723124
*of Rust
or linking like >>61723107 says
>>
>>61723051
threads is of type Thread* which was passed in an argument as this piece of code resides in a function. I dont wanna show the whole thing cause I might get fucked up or something by my uni.

But basically its:

some_function(Thread *thread){
...
...
while loop{
the code ive shown
}
...
}

The purpose of me going threads[prev thred % NUMTHREADS] is because I actually have a circular linked list, and I basically want to take one node out of the circular linked list and reattach where the pointers should go, so I can't do what youve shown.

threads is an array that contains pointers to other threads e.g

threads[0] = a pointer to a thread struct
threads[1] = a pointer to another thread struct

I hope this makes sense
>>
>>61723133
>>61723123
>>61723107
Apparently Rust does static linking by default.
>>
>>61723072
Theory mostly. I can kind of sort of work with OpenGL but I have no idea why it's structured like this or what I'm really doing.
>>
>>61723102>>61723091
>DHCP/ARP
Kicks the ass of my response
I was about to talk about spending 2 hours writing a pinging program and scrapping it because of how slow it was.

I was making a service to allow instances of my program to detect others on the same network.
>>
>>61723107
I just tried clang with static linking and it didn't change anything.
>>
>>61723171
Ok.

http://www.adriancourreges.com/blog/2015/11/02/gta-v-graphics-study/

Here you go. My hope if you at least feel a little bit better after this. Not sure how modern school courses are though with graphics, but I think this blog is a great introduction.
>>
>>61723149
gotcha. You can avoid unnecessary reference complications by referencing through your currentThread like this:
Thread *cthread = (threads + currentThread)
cthread->prev->next = cthread->next;
cthread->next->prev = cthread->prev;
>>
>>61723176
nmap would have done it though. I used it to scan for EternalBlue on my company's network. Takes a while but it's been optimised for decades and the task is a slow task in itself.
>>
>>61723198
Thanks anon, my school doesn't even teach graphics so idk either.
>>
>>61722378
glib strlen is faster than yours, ironically
>>
Rust is going to replace C/C++/Java/C#. Prove me wrong.
>protip you can't
>>
>>61723208
my bad I forgot the ; on that first line
>>
>>61722732
>>61722934
I don't think you can use longjmp to implement coroutines if that's what you're looking to do.

Longjmp works by just hard setting the stack pointer I believe, and I think you can only jump up the stack, and things lower down get overwritten quickly. So you'd have to structure your code really strangely and you'd have to use an actual stack structure rather than automatic variables on the stack.

It's no call/cc.
>>
>>61723102
>>61723176
Thanks I think this will help. Just that we have about 900 connected devices within our network(s) across 4 different buildings so we got alot of routers and switches, and always in need of more.
>>
>>61723209
Ended up getting an epiphany after using the event pattern on a different project.

Scrapped the brute force ping approach and used broadcast / listen. Costs almost nothing and is really easy to scale.
>>
>>61722982
>(_, _) => println!("{}", i)
Top quality garbage right there. Fits well for /g/ tards
>>
>>61723227
It's also many orders of magnitude larger. Include a couple of headers and your binary size already bloats up to several hundred KBs.
>>
>>61723048
>211
>>61722982
>206

Looks like near zero cost abstraction to me
>>
>>61723254
C's include system is completely retarded
>>
File: 1376182921994.jpg (65KB, 445x488px) Image search: [Google]
1376182921994.jpg
65KB, 445x488px
>>61723254
>Including headers bloats binary size
>>
>>61722378
What are some cool task automation ideas with python?
>>
>>61723254
>several hundred KB
>not on an embedded system, but a PC
That's terrible!

If I have 100,000 such executables then that's whole season of anime down the drain! And 100,000,000 such executables would completely use up my hard drive space!
>>
>>61723288
Automating shitposts or /dpt/ threads.
>>
>>61723288
automating the suggestion of tasks to automate
>>
C novice in need of help understanding this

struct point{
int x;
};

struct point p1, p2, p4, p6;
struct point *p3 = &p2;
struct point *p = &p1;
struct point *p5 = &p4;

p3->x = 17;
p4.x = 5;

printf("%d\n", p5->x);
printf("%d\n", (++p5)->x);



If I wrote this snippet correctly and sufficiently, the first print statement gives 5 (simple enough) but why does the second print statement gives 17? It comes from p3 of course, but I'm confused about what the pre-increment makes the struct point get. Declaration order doesn't seem to make a difference.
>>
>>61723350
p2 is adjacent to p4 in memory. Learn how a linear memory model works.
>>
>>61723288
What you wrote is undefined behavior. You got a weird result because you did something weird and illegal.
>>
>>61723350
That's undefined behaviour.
It just so happens that p4 and p3 live next to each other in memory, so you happened to read p3.
>>
How is Fortran faster than C?
>>
>>61722378
4chan browser for android, lets you filter out canadian posts
>>
>>61723208
>>61723232
Thanks I get the logic of this, I don't know why I didnt think about this, but I keep getting an error where it says

>*cthread is a pointer did you mean to use `->`?

Ive tried Thread *cthread = &(threads + currentThread)

but that didnt seem to fix it, any ideas?
>>
>>61723371
>>61723375
Got it. My class is some C and mostly ARM, so I'm making sense of how C compares.
>>
>>61723397
did you do cthread.prev? You're supposed to use ->
>>
>>61723389
It used to be for basically only linear algebra because of the aliasing rule. Now C has the restrict keyword so C should be on par for linear algebra with a compiler that actually implements that pragma.
>>
>>61723347
>>61723326
kek
but srsly any ideas?
>>
>>61723422
Sorting your pornography collection is a particular useful task to automate.
>>
>>61723412
Tried both, how you exactly did it and cthread.prev -> next
>>
>>61723406
The order that globals are specified in C does not have to correlate at ALL in C. The compiler can put globals wherever the fuck it wants and in whatever order it fuckin feels like.

A 10 dword array in C is distinct from 10 sequential dwords. Not like assembly in that regard.
>>
>>61723434
what happened on the first try?
>>
>>61723440
>Thread *cthread = (threads + currentThread)
>cthread->prev->next = cthread->next;
>cthread->next->prev = cthread->prev;
yields the error did you mean to use `->` and same with other
>>
>>61723436
>>61723406
Some code to illustrate
$ gcc -o undefined undefined.c
$ ./undefined
5
17
$ gcc -o undefined undefined.c -O5
$ ./undefined
5
0

-O5 just means "optimize this as much as you possibly can." The upshot is the assembly is different. Since you know ARM, you should be able to sorta read x86 kinda and see for yourself.
gcc -S undefined.c
outputs assembly in AT&T syntax. And for non-shit Intel syntax,
gcc -S undefined.c -masm=intel
>>
>>61723471
show the compiler output
>>
>>61723475
>O5
It only goes up to O3. Every thing above 3 gets treated as 3.
>>
File: 1dsafsdfa.png (270KB, 790x978px) Image search: [Google]
1dsafsdfa.png
270KB, 790x978px
>>61723481
>>
>>61723428
That's actually an interesting though desu. You could automate downloading images from particular tags from boorus and train an AI to recognize tags, then have the AI classify your scattered porn.
>>
>>61723436
>>61723475
alright then
>>
File: vlcsnap-error285.png (2MB, 1920x808px) Image search: [Google]
vlcsnap-error285.png
2MB, 1920x808px
WASM/DOM interop when?
>>
>>61723509
How is Thread defined?
>>
>>61723523
It can't come soon enough.
>>
How can you tell when someone is a coding genius
>>
File: asdf000.png (24KB, 535x206px) Image search: [Google]
asdf000.png
24KB, 535x206px
>>61723524
I believe this? Im new to C so im not entirely sure
>>
>>61723532
when they can easily fix your shit code
>>
>>61723509
>conflicting types for 'printThreadStates'
I'm going to take a punt and say you have a syntax error somewhere before that function (probably a missing semicolon) and it's causing the rest of the parse to come out as garbage.
>>
>>61723508
Oh well. My lisp compiler does have O5 so I've gotten used to doing -O5 for "hella messed up." I haven't really read what the optimization knob does in GCC, but in my lisp compiler, O5 does disable functionality so I've actually read that one.

Interesting though. Glad it's been silently downgrading my 5s to 3s though.
>>
File: zeromq-logo.png (5KB, 402x146px) Image search: [Google]
zeromq-logo.png
5KB, 402x146px
I'm currently using ZeroMQ for messaging and I'm happy with it.
The problem is that I want to eventually have browser clients that connect to it, but ZeroMQ doesn't have a proper JS library (with CurveZMQ support, etc.).

What's the solution for me? Should I use another separate library for browser clients only?
I need pub/sub and req/rep patterns, by the way.
>>
>>61723538
>typedeffing a pointer
Please NEVER do this.
Expanding out your declaration:
Thread *cthread = (threads + currentThread);

struct thread **cthread = threads + currentThread);
>>
>>61723555
Typedefing a pointer makes sense if you're writing a library and want to make an object totally opaque.

I think anon is writing a coroutine library judging by the jmp_buf
>>
>>61723542
If i comment out the code you gave me it still compiles and runs fine even with garbage output

>>61723555
I was given the header file so I have no choice but to use it, Im not going to risk changing it
>>
>>61723571
yes I am writing a thread library example for my assignment, its pretty interesting but Im just so fucked off right now because of all these trivial nuances that do nothing but waste my time
>>
>>61723571
You don't need pointer typedefs for opaque structs.
It just causes surprises when something that looks like a value can get modified by some function.
void my_fn(sometype value);

Any sane programmer will think that this will NOT modify the value outside the function, but if you typedef pointers, it probably will.

Just use a pointer to an opaque struct.
>>
>>61723584
if that's the case just define cthread like this:
struct thread = (threads + currentThread);


and keep the rest of the code as I gave it earlier and it should work. Sorry for not seeing struct thread was a pointer already
>>
>>61723600
Kinda messed up they're making you do it in C first desu.

Anuway I think I know your issue

Thread * is actually a **.

try cthread[0] instead of cthread. But don't do prev[0] because that's just a *.
>>
File: WHY.png (77KB, 830x548px) Image search: [Google]
WHY.png
77KB, 830x548px
>>61723616
I dont know what the problem is this time.

THe purple error is just a warning for something else that I dont know and dont care about so ignore that
>>
>>61723688
oops struct thread cthread
>>
>>61723663
Cant just do cthread[0], it needs to be cthread[variable] if anything cause I needa make this work for any situation

Idk if im making any sense at this point im malfunctioning at this point its been 2+ hours with this
>>
>>61723688
>struct cthread
isn't a type. Struct is a weird (stupid) keyword in C that means "look in the struct name table instead of the variable nametable"

I'm pretty confident doing
Thread * cthread = ...;
*cthread -> prev -> next = *cthread -> next;
*cthread -> next -> prev = *cthread -> prev;
currentThread = *cthread -> next -> tid;

will work
>>
File: LMAO.png (189KB, 737x918px) Image search: [Google]
LMAO.png
189KB, 737x918px
>>61723703
>>
im not doing exclusively cs as my degree, but do you think i should get a laptop? currently just hand writing my notes and stuff.
>>
>>61723712
cthread[0] will (probably?) work. Cthread isn't an array. It's a double pointer. doing [0] just dereferences it. You need to dereference it twice since it has double indirection.
>>
operator precedence should be whitespace sensitive
prove me wrong
>>
>>61723736
No your grades will suffer. Handwriting has been shown to be better for memorization than typing AND you'll end up fucking around on a laptop.

>>61723740
Lisp.
>>
>>61723735
we did it the other way around this time. It's late for me too. sigh. struct thread *cthread and Thread cthread are the same

so
Thread cthread = (threads + currentThread);

and we should be golden
>>
>>61723747
Lisp doesn't have operator precedence at all.
>>
>>61723738
>>61723721
Doesnt work, both give that same you meant to use ->? error
>>
>>61723740
i can't

3                     *                    2+4  -  3
>>
File: pepe university.jpg (8KB, 250x234px) Image search: [Google]
pepe university.jpg
8KB, 250x234px
>>61723759
>IT FUCKING COMPILES
Segmentation fault (core dumped)

Im fucking done lmao.
>>
say i have something basic like
(+ 2 1)
how does the compiler and cpu actually do that?
>>
>>61723760
That is my counterpoint. Lisp is the best language and it doesn't have operator precedence because operator precedence is a disgusting assault on readability.

That misfeature is inherited from math, which inherited that from noun verb object sentence structure which came about because people got too lazy decline their nouns. The only reason people are more comfortable with math notation is either because English was their first language or because they were forced to learn math notation in elementary school.

It's like base 10 vs base 12. Base 12 is technically superior but base 10 is what's used even in science because elementary school teaches base 10. EVEN THOUGH you can count base 12 with your fingers no problem.
>>
>>61723817
>...Lisp is the best language...
go to bed grandpa
>>
>>61723805
put values into registers, add, and done
>>
>>61723805
This is actually a massive question. You should be more specific about what you want to know.
>>
>>61723805
Well you can interpret that pretty easy if you have a working lisp environment. Look up the metacircular evaluator. So the hard part is writing the first lisp environment.

But compiling lisp is really hard. The compiler I use transpiles it to C code. This is
(+ 1 2)
transpiled to C:
https://pastebin.com/StHQ5d9f
I don't expect you to be able to read that. I can't either. Machine generated code is hell. All the extra lines are setting up the garbage collector and the environment. (+ 1 2) is actually line 138.

Chicken is particularly hellacious to read compiled code for because of how it does tail recursion. Everything is translated to continuation passing style and instead of using the stack normally and using the return keyword, it longjmps all over the place like a coked out rodent, letting the garbage collector fix up the stack.

Recommended reading: dragon book, and for lisp in particular http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.39.4206
>>
>>61722378
whats the consensus on React Redux?

just been offered a huge contract if i can learn it within a week
>>
>>61722401
Refactoring glibc.
>>
>>61723903
how does the compiler make it work, i know it makes a binary that the architecture understands ut how and what

>>61723923
ill read that book but this raises more questions, like why the intermediate step of conversion to c before undoubtedly being converted again
>>
File: AHHH.png (289KB, 1736x768px) Image search: [Google]
AHHH.png
289KB, 1736x768px
Does anyone know what causes this segmentation fault?

Also what are segmentation faults?
>>
>>61723986
data struct for "thread" type here >>61723538
>>
>>61723971
>how and what
Compiling is a massive field in itself, filled with a lot of theoretical CS.
It's too advanced for me to go into any real detail in a 4chan reply.

Massively oversimplifying, it reads in text, parses some sort of structure out of it, and then tries to output something (usually assembly, but not always) with the semantics defined by the input text.
>>
>>61723971
Well it's easier to write a garbage collector in C, and it's easier to use longjmp in C, and longjmp is necessary for the tail call optimization strategy used. C is just easier to work with. You also don't have to worry about a lot of assembly optimizations that you'd otherwise do yourself since gcc will take care of them.

I'd recommend looking up the metacircular evaluator first though. It's an interpreter but you'll get a better understanding of how lisp actually works.
>>
>>61723986
>Also what are segmentation faults?
memory access violations. Poke a region of memory that you're not allowed to and you segfault.
Usually it happens when you dereference a null pointer.
>>
>>61723735
what is that color scheme called in the top
>>
>>61723986
>also what are segmentation faults
Holy fuck they really threw a green man deep into the weird corners of C.

A segmentation fault is when you try to access data that's on a page your program doesn't own.

Usually null pointer exceptions, array out of bounds exceptions, and trying to read freed memory exceptions.
>>
>>61724042
>Usually null pointer exceptions, array out of bounds exceptions, and trying to read freed memory exceptions.
Jesus christ. This is so inaccurate and stupid (in the context of C) that is hurts.
>>
>>61724053
>is hurts
it hurts*
>>
>>61724042
>>61724060

This is a student at the University of Auckland taking the easy way out of a Computer Science paper in the second week. He should stop posting immediately before he finds himself dealing with the consequences of breaching an AS-75
>>
>>61724060
Compile your program with debugging flags (-g).
Run your program through valgrind or some shit, and see which line it crashes on.

Learning to debug your own programs is an important skill.
>>
>>61724089
Im not 'taking the easy way out', look at my posts.

see >>61723600

All I want to do is get this nuance done with, the logic of it is not hard at all I just dont understand why it doesnt work in C.

Ive worked on this myself for a long time before I even posted here, it was a last resort since the tutor hasnt responded.

But Ill stop posting anyway.
>>
>>61724154
i've scrubbed your screenshots and am prepared to forward them to Robert with your UPI

im sick of fucking cheaters in this fucking class, dont fuck with me cunt
>>
>>61724154
follow this advice>>61724093
>>
>>61724053
Are you retarded?
$ gcc -o retarded retarded.c
$ cat retarded.c
#include <stdio.h>
int main() {
int * retard = 0;
printf("%i", *retard);
}
$ ./retarded
Segmentation fault
$ cat retarded.c
#include <stdio.h>
int main() {
int retarded = 1;
printf("%i", *(&retarded + 1000000000));
}
$ gcc -o retarded retarded.c
$ ./retarded
Segmentation fault

The last one is hard to replicate in a short example but I'm sure you know why since you're an expert C programmer who knows all about how malloc works right? :^)

OH. I know what it is! You're autistic and you get upset when people use the word "exception" because you insist that it only refers to a certain class of objects in Java and C++! Educate thyself autist:
http://perldoc.perl.org/perlglossary.html#exception

>>61724089
I think it's an institutional problem if a student somehow got into a senior level course with no exposure to how operating systems work.

There's no fucking way a freshmen is going to throw longjmp at students week 2. So have fun being a l33t doxxer.
>>
>>61724183
Why the fuck are you linking the perl docs?
>>
File: Screenshot_20170804-095121~01.png (337KB, 959x1450px) Image search: [Google]
Screenshot_20170804-095121~01.png
337KB, 959x1450px
>>61722378
You're missing the best bit op.
Anyway. This is a good lesson on why you shouldn't use null terminated strings. It didn't make sense back then either. There's much more efficient constructs with similar memory overhead. Sure, the worst case for null termination is great. 1 byte. But it's not realistic to assume you'd fill memory with one long string.
>>
>>61724197
Yup! Autistic!
>exception
>A fancy term for an error. See fatal error.

If you think that this is an invalid use of the word exception, then explain to me why "Exceptions" in C++ and Java are called "Exceptions" and not "ErrorStateObjects" or something.
>>
>>61724183
i have a CS degree from a US uni and we did indeed only have 1 OS class and it was at the very end of the program.

it was also the only course we had that required us to program in C at all. we had an elective "systems programming" course that used C as well as a networking class, but they also allowed java for anything that could be done in java

some programs just suck dick man
>>
>>61724175
This thread shows I have no intent of intentionally cheating within reason, all I've asked for is why a simple line of code does not work. As you can see I have done everything myself except for that one line, I also have put in a lot of effort before this.

Forward me if you want, I have nothing to hide, I think all my posts were pretty reasonable, in fact it would be rather hard to ask for help in the current context using just text (Which I had tried as my starting post) hence why I had to show screen shots.
>>
>>61724183
>perl
You were talking C. Anon was writing C.
Why drag perl into this?
>>61724210
C doesn't have exceptions. Some platforms can translate page faults into exceptions, which I'm sure you could catch in C. But it's silly to throw confusing word choices at anon.
>>
>>61724207
Actually it made perfect sense to use null terminated strings back then. You could iterate down them without having to waste a register slot on an int for a size.

And since strings are primarily used to store text, which is typically rendered whole onto the screen, it makes sense that you'd spend most of your time iterating down strings and not doing strlen on them.
>>
>>61724210
>Use non-standard terminology
>Hurr you're wrong, you should have known
You're definitely the autistic one.
>>
My uni had assembly and C mandatory I'm the first year, then multithreaded C in the second year, then an embedded systems course with only assembly and C89 in the third year

We also learned python, Java, C# and Erlang across the years

UK uni for context
>>
>>61724228
why delete your post then? you know there's several archives yes?
>>
>>61724234
Exception is a fancy word for error! That ain't just for perl. That's English. It was the first link that came up when I googled "define exception"

>exceptions
>catch
You don't have to catch exceptions. They're just errors, which happen to be conceptualized as objects in Java. And you can catch exceptions in C on Linux pretty easily by overriding a signal handler; you can even emulate a try/catch block very cleanly with longjmp.

Why are you trying to confuse him by bringing DOS and C64 into the picture? On any system he'd likely use, the program crashes when you go out of bounds.
>>
>>61724252
pretty narrow view
>>
>>61724275
See >>61724242
>>
>>61724252
We learned Java in the first year, and were also just kind of expected to pick up Python and PHP. No C until second year.
>>
>>61724283
You're never going to change what words mean. This isn't France where there's a governing body that dictates the meaning of language.
>>
>>61724280
In what way?
>>
>>61724292
See >>61724242
>>
>>61724280
why are languages like java and python so widely taught when theyre bloat that obscure you from programming well because of virtual machines?
>>
>>61724306
easiest way to get a job
>>
>>61724306
>babbys frst language
>object oriented programming easy mode
>>
>>61724299
You're never going to change what words mean. This isn't France where there's a governing body that dictates the meaning of language.

American imageboard: free non-government regulated language :^)
>>
>>61724306
Because you can get shit done in them regardless
>>
>>61724275
>I'm using English
Yeah. I know exception is an English word. But in the context of C and C++ as you brought up its just confusing.
>dos and c64
I didn't bring that up.
>the program crashes when you go out of bounds
I'm not falling for this trap. You're gonna pretend you mean out of the memory page you're allowed to touch but the normal interpretation of this would be a higher level construct like array bounds.

You're just a very mean person who wishes to confuse a new programmer. I hope you get some hurt back.
>>
>>61724306
People put money behind them. Nobody puts money behind promoting functional languages or C.

Python for instance just blew up out of nowhere with no major changes to the language for over a decade. I don't see why that'd happen at all if there wasn't money put behind promoting it.
>>
File: 3842738471234.jpg (167KB, 1024x768px) Image search: [Google]
3842738471234.jpg
167KB, 1024x768px
>building for x64
>passing float by value
>code review changes it to const ref float because "that's how it's supposed to be"
why does this industry attract so many morons
>>
>>61724407
People are taught dogma in schools and everywhere else.
Really most fields are like this. Most fields don't work at a high enough level that their errors won't be immediately obvious to them though.
>>
>>61723986
>gdb a.out
>run
>bt

show results
>>
>>61724407
fucking why
why would you copy a pointer that's bigger than the data it's trying to modify if you're not mutating
>>
>>61724407
C++ programmers are all morons.
It's certainly no surprise.
>>
>>61724446
no u
>>
>>61724368
Oh yeah I'm being deliberately mean by not playing your language games.

Don't pretend to be virtuous when you're just an asshole anon.

I'm sure that the best way to tell someone why an error occurred is to go deep into the bowls of how linux works and talk about virtual paging rather than frame it in errors that he knows.

But in reality you don't care about that. You're a retard who thinks that C errors (on modern computers) aren't exceptions because you really don't know how your computer works (you can override sigsegv!). Your terminology "corrections" are just an attempt to boost your confidence about your knowledge of C when you really don't know shit other than enterprise tier fizzbuzzing.
>>
>>61724442
That's not even the real problem usually. Passing in pointers to functions hurts what the compiler can do. Aliasing and all that.
>>
>>61722933
>using global variables
>do while(0)
Were blocks not allowed in C at some point?
And even if they were, there are no variables created, so I don't see the point in the block.
Does anyone know?
>>
>>61723986
>>61724428
nvm I just saw what's wrong

if (cthread -> prev)
cthread -> prev -> next = cthread -> next;
if (cthread -> next)
cthread -> next -> prev = cthread -> prev;


This will make sure the structs actually exist before looking into them. The reason it segfaulted is the next or previous struct didn't exist, yes you tried to put something in it.

if cthread->next or cthread->previous don't exist, their value will be NULL, if (NULL) is false. Just to clarify.
>>
>>61724476
do while(0) is a hack to get around preprocessor limitations I believe.
>>
>>61722933
where do you see a global variable?
>>
>>61724466
>I'm sure the best way...
Only part worth replying to.
His error is best not described in terms of a construct that's not relevant to his environment. It doesn't matter what you think the low level details of it is. He was asking what a segfault is and he's writing C. The correct answer simply isn't that it's an exception. Intentionally harming others is a very low thing to do anon.
>>
>>61724492
>>61724476
meant to reply to this
>>
>>61724497
Continue faking virtuousness anon! Maybe you'll fake it until you make it and realize that you've been a cunt you whole life.
>>
>>61724492
p and str are not defined in the context of the function.
You can't use this function in any other context
>>
>>61724552
It's defined in the function. Just not in the macro.
>>
File: 0HlXVnX~01.jpg (31KB, 338x504px) Image search: [Google]
0HlXVnX~01.jpg
31KB, 338x504px
>>61723545
Bump.
>>
learning webpack and babel
kill me
>>
>>61724552
It's not a function, it's a preprocessor macro. Every instance of testbyte will be replaced by this block, and every instance of x in that block will be replaced by the first argument of testbyte. So p and str only need to be defined in the function it's used in.
>>
Use a language you can trust, use a language not covered in dust, use the language Rust!
>>
>>61724627
I know.
>>
>>61724639
more like bust language
>>
>>61724646
You didn't seem to since you assumed that the variables had to be defined in the preprocessor macro.
>>
>>61724666
no, I just pointed out that the macro needed the variables to be created out of the scope of the function.
I see it all the time in scripting languages too (where everything also is just literal copy/paste)
I am not saying it won't work, I just say it is a lazy design
>>
>>61724770
.....It was literally made to not have to type it for each individual byte like in OP's pic

Also it's a fucking libc, one file is one function, and the macro is defined for that file only. This is perfectly fine.
>>
File: 11mzuw.jpg (92KB, 1500x846px) Image search: [Google]
11mzuw.jpg
92KB, 1500x846px
>>61722378
>2000 + 10 + 7
>STILL no
.enumerate()

The power of """""""""""""""modern""""""""""""""" C++
>>
>>61724813
>proposing to use a lazy, costly function in a libc
>C++
>>
How do people keep up to date with new webdev stuff

Are there websites that i should be daily browsing? Because I feel like I'm always late to the party on new stuff.
>>
>>61724847
C++ doesn't care about cost, drop that bullshit
>>
>>61724847
>lazy, costly
>>
>>61724858
You're talking about a standard C library, the one that most software built for most Linux distribution is linked to, it's made in C.

And you're complaining that it's not using an enumerate() function. And you think that it's C++.
>>
>>61724813
What is that supposed to do?
>>
File: 94829472134782342.jpg (14KB, 325x258px) Image search: [Google]
94829472134782342.jpg
14KB, 325x258px
Do people unironically use "fileName" instead of "filename"?
>>
>Sitting in a heated bed, reading a book on shell scripting
Being a NEET has never felt so good.
>>
>>61725336
I-I don't, my smug anime friend...
>>
>>61725358
How do I become autistic enough to enjoy reading boring shit
>>
File: Bjarne-Stroustrup.jpg (27KB, 494x423px) Image search: [Google]
Bjarne-Stroustrup.jpg
27KB, 494x423px
When are they shoving in linear algebra in the standard?
>>
>>61725420
The year is 3053.
1/4 of the Sol System is part of the C++ standard library.
>>
File: shirt_off.jpg (51KB, 687x1024px) Image search: [Google]
shirt_off.jpg
51KB, 687x1024px
>>61723227
>>61722593
>>61722551
>>61722735
>>61722933
This is musl's strlen. Is it good?

#include <string.h>
#include <stdint.h>
#include <limits.h>

#define ALIGN (sizeof(size_t))
#define ONES ((size_t)-1/UCHAR_MAX)
#define HIGHS (ONES * (UCHAR_MAX/2+1))
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)

size_t strlen(const char *s)
{
const char *a = s;
const size_t *w;
for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a;
for (w = (const void *)s; !HASZERO(*w); w++);
for (s = (const void *)w; *s; s++);
return s-a;
}
>>
>>61725456
maybe
>>
>>61725456
yes
>>
>>61725456
no?
>>
>>61725456
It's basically the same thing as glibc's but it's far less understandable due to lacking comments that explain the magic and an abuse of macros to make the code "look" pretty.

The only reason I know what it does is because I read the very long comments in glibc last time we had a shitpost thread about glibc.

2/10.
>>
>>61725456
This is OpenBSD's, it's what you'd expect anyone who has a basic concept of C to write.

#include <string.h>

size_t
strlen(const char *str)
{
const char *s;

for (s = str; *s; ++s)
;
return (s - str);
}

DEF_STRONG(strlen);


OpenBSD's not particularly concerned with speed in their projects though. Security through simplicity and all that.

To answer your question, it seems to somehow need many headers for it but it's fine as they're all compiled in the same library. I think it's similar to the GNU and FreeBSD libc with the HIGH & LOW except it's kept in a loop instead of being unrolled.

One thing I just noticed is that glibc and freebsd libc implementations both nest their loop (even if it's unrolled) to prevent any false alerts in the algorithm, but musl assumes that the first word containing a zero according to the high&low strategy is the right one, which is not very safe but conceptually I don't think it would happen.
>>
>>61725570
Simply beautiful.
>>
>>61725582
The algorithm used by musl, glibc and freebsd is more efficient with any input longer than a word (8 chars) though, as it searches for a zero in a whole word instead of byte by byte. OpenBSD just doesn't mind being slow as it's not their project goal. Different design philosophies.
>>
>>61725570
What does
 DEF_STRONG(strlen);
do?
>>
>>61722732
What the fuck is a pointer? Ive been studying python for 6 weeks as an expert and have never heard of this
>>
>>61725631
It would be related to linkage and symbol visibility.
You can't define standard library functions like normal functions.
>>
>>61725637
You already have them.
>>
>>61725637
>Python expert
Does your brain still function?
>>
>>61725631
that's just library stuff
>>
>>61725642
Does OpenBSD have it's own compiler or does it use gcc?
>>
>>61725570
>for (s = str; *s; ++s)
> ;
I've never thought about ; like that. I know ; is NOP but I've never seen anyone write the ; on a separate line so I've always just assumed ;i'ing a for or while loop was special syntax.

Interesting. It makes sense though. Makes it explicit what exactly you're doing and that it's not just some obscure syntax.
>>
>>61725654
How come musl doesn't do it then?
>>
>>61725660
Maybe it'd be clearer if you did {} instead. Whatever.
>>
>>61725668
Either the person who posted it didn't include it or they handle these things differently. I'm not aware of the details on how openbsd is built and linked.
>>
File: 1493201269833.png (72KB, 180x530px) Image search: [Google]
1493201269833.png
72KB, 180x530px
I can't "think in C++". The only thing I can do is "think in D"

What do?
>>
>>61725420
Man, he looks much better with a beard.
>>
>>61725692
Remove Garbage from your brain.
>>
>>61723288
scrape 4chan for easter toads
scrape porn forums for the best cuck porn
tweet about niggers and jews
automatically organize your torrents/files into a media library with thumbnails and subtitles


there's some
>>
>>61725684
{} is ugly. I like the openbsd style more desu.

It's pretty nice. I'm going to refactor my code now.
>>
>>61725692
if you can only think about the D maybe it's time for you to buy a mac
>>
>>61725643
What, 6 weeks? Yes

>>61725644
What do you mean? If not mine, wouldn't everyone else's be non functioning?
>>
>>61725701
The collector already does that for me
>>
>>61725709
eh, OSX isn't all that bad. I don't like how they restrict their OS to specific hardwares so I'll stick to Linux.
>>
>>61725724
As long as you use D, you will clog it up with garbage.
>>
>>61725637
Same poster even though I said I'd stop posting - Basically a pointer is a reference to a location in memory, think of it this way, you want to go to your house, but where is your house? You have an address, street number, mailbox number, basically something that can identify where something is.

So in the context of C, if I have a variable, we know it is on the stack somewhere in memory, a pointer is the coordinates to this point in memory which you can then do whatever you want to the variable.

The reason you haven't heard about pointers in python is because you dont get access to them directly (as far as im aware), all the nitty gritty stuff is taken care of you under the hood so you can focus on 'high level programming'
>>
File: 41234234123.jpg (54KB, 610x448px) Image search: [Google]
41234234123.jpg
54KB, 610x448px
>>61725692
have you tried dressing up as a japanese schoolgirl? It improves programming ability. It's a scientific fact!
>>
>>61725733
That's what blood is for. The brain produces garbage at the highest rate of any organ. That's one of many (many!) reasons why neurons die first when your blood stops flowing.
>>
>>61725759
delet this
>>
>>61725728
I was just making a gay joke, I'm well aware of how good macOS is
>>
File: 12837812381273.png (1MB, 1156x1156px) Image search: [Google]
12837812381273.png
1MB, 1156x1156px
>>61725766
>he doesn't have a set of cute pantyhose in his drawer for the most intense of programming
>>
>>61725783
Stop turning me gay
>>
>>61725783
I'm ok with traps actually, so plox show your benis.
>>
>>61725781
>opera
>>
>>61725748
Okay, so I was trolling originally but since we're on the subject: I took C++ in college in a programming prerequisite for engineering, and we studied pointers. I get what they do, but what I don't get is their purpose. Mainly, why call a pointer instead of just calling the variable itself?

Thanks for the great explanation btw, I really dug coding in college but never took it seriously until recently. Been fucking around with Ruby a lot lately.
>>
>>61725794
They're all shit performing botnets anyway might as well choose the one with the most features
>>
>>61725792
I feel sorry for traps. Once they get old their skin and shape turns shit and can't remain cute anymore
>>
>>61725798
As mentioned I am not very familiar with C so I can only give you a surface level answer.

Cheap answer: C is an extremely efficient language as modern compilers are amazing these days, so learning to use C and obeying their rules leads to more efficient programs processor wise, thus you must understand pointers if you want a program that is scaleable and fast (think of scientific computation).

Better answer: Architecture of the machine - in the end game all your data and everything you do on a computer correlates to hardware, somewhere on the computer your '24' is stored in an adder somewhere (transistor?) and you need to keep track of where everything is. You say 'whats their purpose', it literally is to find where everything is, how do you just "call the variable itself"? If the variable correlates to something stored in hardwear, where is this hardware?

I believe it goes like that.

Basically, the more complex a language gets (C vs Python) the more abilities you have to meddle with hardware
>>
I'm a very unhappy teacher now and decided to become a programmer. Aiming to get an internship later this year or early next year after attending a course (learning + networking + seeing some real life problems developers face is worth the money to me) and working on my own.

I decided on C# because this and Java are two main languages needed in my area. The rest are web/frontend/javascript/etc jobs and I feel I'm underqualified to take on both coding and designing things.

So far it's been going well but I'm getting into the basics of objective programming and still trying to get the hang of it. But hey, for me anything is better than teaching.
>>
>>61722853
>jdownloader/python

is this a ruse? I have no idea what you are doing, but surely wget/curl/awk/sed would do it just fine
>>
>>61725791
Appreciating a feminine penis is NOT gay
Feeling the smooth silky fabric rolling up your thighs and entrapping your limp little cock is 100% OK. Even Knuth would recommend it in his lectures.

>>61725792
this is a blue board
>>
>>61725798
Most languages use reference types. Take Java. In Java, objects are allocated exclusively on the heap and object types are all reference types.
Foo foo = new Foo(); // new obtains a reference to a newly created object. foo stores that reference.
Foo foo2 = foo; // foo2 refers to the same object as foo.

C and C++ treats everything as values by default, not references. There's no garbage collector to determine when all the references to an object are gone.
Foo foo; // make a foo object
Foo foo2 = foo; // copy the whole object. foo and foo2 are simply Foo, not references to Foo

If you want reference semantics, you must be explicit about it.
Foo foo;
Foo *fooptr = &foo; // Refers to the same foo

I can give a pointer to an object if I want to avoid copying it, or if I need to mutate it.
There's also pointer arithmetic for arrays.
>>
>>61725798
Pointers probably don't seem as practical because you took C++ and not C.

One use of pointers is fucking with data that was handed to you. Memcpy is the typical example. It writes data from one region to another. And those regions are marked with pointers.

Another use is not having to copy large things. Suppose I have an uncompressed 1000 by 1000 image: 4 megabytes. Rather than copying 4 megabytes every time I give it to a function, I just pass an 8 byte pointer.

Another use is you can fuck around with the order of data without disturbing it.

A simple example is suppose you have a list of objects that you want to sort. But you want to sort them without actually moving them around. Maybe because other parts of the program have pointers to those objects. Maybe because your program is multithreaded and moving them is going to fuck you up with race conditions.

The solution is to make a list of pointers, and sort the pointers.

There's some data structures that only really make sense with pointers, like queues:
https://mitpress.mit.edu/sicp/full-text/sicp/book/node62.html
>>
>>61725843
Cheers, appreciate the time you took even when not being super C familiar. I guess I just wonder how the address of a variable or piece of data would be used in a program. It sounds like something that would be useful but can't think of an example I suppose.
>>
>>61725857
>this is a blue board
Damn you, first you tease then you deny. Like a damn woman already.
>>
>>61725872
>Pointers probably don't seem as practical because you took C++ and not C.
I don't understand. Pointers are just as important to C++. Polymorphic OOP doesn't work without reference semantics.
>>
>>61725872
>The solution is to make a list of pointers, and sort the pointers.

Everything now makes perfect sense
>>
I watched this video https://www.youtube.com/watch?v=zW_HyDTPjO0 and now I have a question. Can I do the same in bash? I mean, test C code in bash?
I googled quickly and found some frameworks for bash to test bash code, idk why someone would like to test bash scripts but alright.
Right now I'm trying to write a wrapper for my C program to take function from STDIN, run it and write its output to STDOUT so I could handle this with one of those frameworks for bash.
>>
Please remove the gay roleplayers from /dpt/

Anime is fine but this is too much
>>
>>61725872
>>61725871
>>61725843
Thanks fellas for the answers, I absolutely get it now
>>
>>61725890
>Like a damn woman already.
Everybody knows men are better than women even in being women.
>>
>>61725926
Women are much better at being attractive
>>
>>61725938
between 17-25
>>
>>61725846
>wget/curl/awk/sed

Is this a ruse?

He is using Python. He should be using the requests module for it.
>>
>>61725951
Do you mean that men are more attractive to men or to women after 25? Even if you like traps, I'm not sure a 30 year-old trap is going to be your cup of tea.
>>
I just covered my mouth to cough and when I looked at my hand it had blood on it. Is this something I should be worried about?
>>
>>61725971
>He is using Python

surely this is a ruse now
>>
>>61725914
I can post an example from some of my code if you'd like:
//menu_instance ** menu_instances;
qsort(menu_instances, menu_mem_cursor, sizeof(menu_instance*), menu_compare);
for(int i = 0; i < menu_mem_cursor; i++) {
menu_quad * dest = menu_quads + i;
menu_quad * src = &((menu_instances[i])->grafix);
memcpy(dest, src, sizeof(menu_quad));
}
glNamedBufferData(menu_vbo, sizeof(menu_quad) * (menu_mem_cursor), menu_quads, GL_STREAM_DRAW);

The position of the
menu_instance*
objects can't be fucked with because another thread is holding onto pointers. Updating the other thread's pointers is essentially impossible.

Sorting pointers to
menu_instance*
objects instead allows me to "sort" them but not fuck everything up.
>>
>>61725986
It's summer so it might be the weather. How much blood? You a smoker? Health insurance?
>>
>>61725972
I'm saying that women are better at being attractive between 17-25, elsewise they aren't better at being attractive.
That doesn't mean a man wouldn't still be more attracted to an older but real woman
>>
Isn't it weird that men are usually attracted to women, and women are usually attracted to men, and being attracted to someone encourages you to have sex with them, and sex between a man and a women is necessary for sexual reproduction? This is too much to be a coincidence. God is amazing.
>>
>>61726029
>buying into ((((their))))) propaganda
>>
File: 1501008010932.jpg (22KB, 287x202px) Image search: [Google]
1501008010932.jpg
22KB, 287x202px
>>61726029
>>
>>61725637
An address in memory friendo
>>
Post:
>OS of choice for recreation
>OS of choice for development
>Programming language of choice
>Development environment of choice (text editor or IDE)
>Do you (primarily) use a laptop or desktop for development?
>Age
>Do you have a job? (Optional: job and salary)
>>
>>61725692
How is D different from C++? Does D still use a garbage collector?

>>61725688
>>61725570
This is Plan 9's strlen
    TEXT    strlen(SB),$0

MOVL $0, AX
MOVL $-1, CX
CLD
/*
* look for end of string
*/

MOVL p+0(FP), DI
REPN; SCASB

MOVL DI, AX
SUBL p+0(FP), AX
SUBL $1, AX
RET
>>
>>61726124
>How is D different from C++?
Generally cleaner syntax.
>Does D still use a garbage collector?
Yes.
>>
>>61722378

I unironically decided to take on SICP.

Wish me luck.
>>
>>61726133
What's the point of D if it has a garbage collector?
>>
>>61726114
>>OS of choice for recreation
Arch
>>OS of choice for development
Arch
>>Programming language of choice
New to the game, so no pref yet
>>Development environment of choice (text editor or IDE)
Gedit
>>Do you (primarily) use a laptop or desktop for development?
Desktop
>>Age
23
>>Do you have a job? (Optional: job and salary)
Sure brap
>>
>>61726140
Wishing it didn't have one so I could use it instead of sepples.
>>
>>61726114
Fuck off NSA
Also
>windows
>windows
>sepples
>vs
>laptop
>20
>no
>>
>>61726148
Why the fuck did they use a garbage collector in the first place if it was supposed to replace C++?
>>
>>61726114
>macOS
>macOS
>Python (really powerful, really great)
>Komodo
>Laptop (MacBook Pro 15-inch)
>27
>Yes (intern at a software development startup, $9.50/hour)
>>
File: free replies.webm (2MB, 720x1280px) Image search: [Google]
free replies.webm
2MB, 720x1280px
Is there a C++ HTTP server library that allows to read request bodies and write response bodies with streams? I want to minimize memory usage at the expense of CPU usage.
>>
File: succubus.jpg (184KB, 960x1280px) Image search: [Google]
succubus.jpg
184KB, 960x1280px
>>61726183
make your own (tm)
>>
>>61726114
>OS of choice for recreation
Depends what kind, Linux or Windows most likely for gaming
macOS for web browsing, multimedia, etc. especially while working on something.

>OS of choice for development
FreeBSD, sometimes in a xhyve virtual machine on macOS on my laptop

>Programming language of choice
situational, either perl5 or C. I couldn't stick to anything modern. I play with scheme sometimes though.

>Text editor
nvi2

>laptop or desktop
laptop ssh'd to a desktop to compile any meaningfully big project that I work on.

>Age
no

>Job
no
>>
File: 1497355531744.jpg (8KB, 236x113px) Image search: [Google]
1497355531744.jpg
8KB, 236x113px
>>61726183
>streams
>>
>>61726219
How else should I handle transferring big files without putting the whole file into memory?
>>
In a Lua program, I need to make a hundred buttons response to mouseovers.
This means binding a hundred events.
How can I do this iteratively?
All the buttons are in an array.
>>
I'm going to start a project where I don't expect a big number of contributors. My options for choosing the primary language are as follows.

1. Use a language in which I am not comfortable with, but it is massively popular and has tons of libraries but at the same time somewhat counter-productive.

2. Use a language that I am most comfortable with, but it is very unpopular and library count is very limited but I can stay comparatively more productive since I know it well.
>>
>>61726114
Windows
Debian/Windows, sometimes osx
C++
VStudio/NetBeans/Xcode
desktop
26
ye
>>
>>61726250
>All the buttons are in an array
Just iterate over the array?
>>
>>61726114
>>OS of choice for recreation
GNU/Linux
>>OS of choice for development
GNU/Linux
>>Programming language of choice
D, C++
>>Development environment of choice (text editor or IDE)
VS Code
>>Do you (primarily) use a laptop or desktop for development?
Desktop.
>>Age
26
>>Do you have a job? (Optional: job and salary)
Yes
>>
All this Strlen comparisons, but nobody using the SSE/AVX instructions which can do it on 16 bytes at once..
>>
File: 039120382103912.jpg (138KB, 838x638px) Image search: [Google]
039120382103912.jpg
138KB, 838x638px
>>61726264
>>
>>61726271
It's the compiler's job to do that, and it's obvious that the glibc implementation is encouraging it to.
>>
File: 981391283921312.jpg (13KB, 300x169px) Image search: [Google]
981391283921312.jpg
13KB, 300x169px
>>61726264
>just iterate over the array
brainlet alert
>>
File: superthumb.jpg (170KB, 683x768px) Image search: [Google]
superthumb.jpg
170KB, 683x768px
>>61726264
Non-smug-anime response:
The challenge is binding those events iteratively such they produce unique responses.

You can do:
buttons[i].MouseOver:connect(function)
But this will mean that there is no way to tell which button your mouse was over.

But you can't do
buttons[i].MouseOver:connect(function(buttons[i]))
Because you can't connect a function with arguments, only one without.

By the way, I lied about the smug.
>>
roll out
>>61726344
>>61726344
>>
>>61726333
>Because you can't connect a function with arguments, only one without.
Make a closure then?
>>
>>61726251
2. trends come and go, remember linus saying using C for git alone was worth it for deterring c++ devs + being productive helps keep focus + you will probably enjoy it more + contributors will care about your project more
>inb4 haskell

1. can only be a priority if you want to monetize like selling support to enterprise cucks or want to get expertise to improve employability
>>
>>61726442
>1. can only be a priority if you want to monetize like selling support to enterprise cucks or want to get expertise to improve employability

I mean a commercial product.

Any half decent dev can work with most non pants on head retarded languages btw, it won't be a problem to hire additional devs if that is a concern for uu
>>
>>61726114
>OS of choice for recreation
GNU/Linux
>OS of choice for development
GNU/Linux
>Programming language of choice
depends on the project
>Development environment of choice (text editor or IDE)
vim
>Do you (primarily) use a laptop or desktop for development?
switched to a laptop recently, using external keyboard because fuck chicklets
>Do you have a job? (Optional: job and salary)
no
>>
>>61726114
linux linux fortran nano desktop 25 no
>>
>>61726114
windows/debian dual boot because gaymes/development
c++, because that's all i know
sublime text or vim
desktop because my laptop broke
19
not yet
>>
>>61726351
????
>>
>>61726114
>Windows
>Fedora
>Python/C depending on needs
>Laptop
>19
>Just started working as a wagecuck for in supermarket. Can't really into junior software dev jobs yet even tho I've tried
>>
>>61727386
>> editor == null
>> -> true
>editor = VSCode. Nice debugging integration with multiple languages and platforms
>>
>>61727386
>>61727406
I also forgot my real age, which is 20.
>>
This is my first time posting in /g/, and I'm not experienced with coding so go easy on me.
I'm working on a small project in javaFX where I need to make an unknown number of buttons that open specific folders from my computer, but I don't know how I should go about declaring each button in a for loop or if that's even what I should be doing
If anybody can give me advice it would be much appreciated
>>
>>61727559
You'll need to declare an array of buttons, then go through them with a for loop, creating each at a time..
>>
>>61727640
I was mainly looking for how to format such an array but I figured it out, thanks anon
Thread posts: 368
Thread images: 45


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