/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

en.cppreference.com/w/c/io/getchar
seriot.ch/parsing_json.php
youtube.com/watch?v=CRUa_09IOVU
youtube.com/watch?v=zPTY1hKq3SU
twitter.com/SFWRedditVideos

First for D

It's an OK joke.

Necrophilia is illegal

Says the one who can't stop spouting dead memes

Friendly reminder that this is your life at any sufficiently large software company in 2017.

His sign needs a semaphore

He's just tired of the degeneracy at the floor.

This is your life at your adult daycare startup!

Did they try to recreate an Indian sweatshop?

What's the best IDE for C/C++?

Microsoft Word

This is the guy that does all the work these people should be doing.

That must be an horrible place to work.

Pelles

For Linux?

MSVS but only if you're on Windows and don't need C++14/17 that much
otherwise just a text editor with a bunch of plugins

>BLM poster
>not a single black person in sight
MUH EQUALITY

lol I thought the same thing first time I saw that pic

Not exactly.
There's plenty of situations where function calls are good. They're more efficient because of instruction cache and other such things.
It's usually referred to as outlining when the compiler takes straight sequential code and pulls it out into functions which it calls.
And it's the reason the compiler doesn't always inline eveything, it's not always the best thing to do.
Yes that's exactly what's going on. The thing is that for operators you in general have very small functions that would be more efficient if they weren't called as functions but rather had their assembly just inserted where the call was. The call is superflous and a function call can be seen as an optimization barrier. It increases the dependency between registers and addresses so the optimizer has less room to move.
So ideally (without regard for executable size) you'd have the compiler inline EVERYTHING and then outline stuff for you as it sees fit. But optimization is hard, it's not really feasible to do that right now.
So while operator overloads aren't actually a problem in the abstract (they shouldn't have performance impacts at all, like any function call) they happen to be very harmful because code that looks like
vec4 a,b,c,d;
d=a+b*c;

Has 3 function calls and potentially an overloaded assignment operator (making 4).
It's very easy to overwhelm the compiler like this.

But as I said. It's entirely valid to use operator overloading, you just have to look at your assembly after the fact when you care about the performance and remove it if necessary.

It's a developing aid. It's unnecessary to write out the non-operator overloading version before there's a performance concern. That's one thing that's very good about operator overloads. Unlike a lot of abstractions they're very shallow so they don't have a large code impact, they're easy to remove when you need to. It's just a copy and paste.

If kill myself if I had a Facebook ™ branded plushy on my desk.

Why am I stuck in the while loop?

#include


count_char(){

long num_of_chars;

num_of_chars = 0;
while (getchar() != EOF)
++num_of_chars;

printf("%ld \n", num_of_chars);

return 0;
}


main() {


count_char();

}

Hugging those plushies is his only emotional relief in this development hell. You'd grow to appreciate them.

>every day I drift further and further from humanity

>And it's the reason the compiler doesn't always inline eveything, it's not always the best thing to do.
Ignoring bugs or the compiler doing the wrong thing. Obviously.
But if it was as obvious as "inline everything" it could easily be done and we wouldn't even talk about this.

I don't know what getchar() is doing.

what's EOF

because the loop waits for you to input a EOL character and you don't.

'\004'

This.

I want to write an HTML parser just for fun. But then it occurred to me: I would have to read the entire file into a string before I could even start parsing, because I don't know where the matching end tag for the currently open tag is. Am I correct in this assumption or is there a more efficient way? I don't really want to buffer the entire fucking file.

Is it possible to create a n number of functional elements in winforms?
I am making a program that reads user input, and upon that, it displays a n amount of elements (one element includes 1 label, 2 radio buttons, 1 image which should change upon the selected radio button and 1 static image), all with different data.

I alrady made it so, that the static picture displays n amount of times, but I dont know if it's possible to create usable radio buttons for the other image.
Please help, I've been working on this for the last week.

Can't you inline the function call in c++?
Kinda like this:
use std::ops::Add;

#[derive(Debug)]
struct Foo(u32);

impl Add for Foo {
type Output = Foo;

#[inline(always)]
fn add(self, rhs: Foo) -> Foo {
Foo(self.0 + rhs.0)
}
}

fn main() {
println!("{:?}", Foo(2) + Foo(5));
}
Output: Foo(7)
In Rust, but the idea is the same.

I thought getchar() adds it at the end of the user input?

In a real-world environment, you don't have a "file", you get the page via http and can parse chunk by chunk.
That being said, you can easily memory map the file, but just think about how long it takes you to open a 7MB jpeg, it doesn't take long and your html file won't easily surpass that. And then there is the fact that you're doing this just for fun and performance shouldn't be a concern anyway.

You can but it doesn't always happen even though it should.
This is all in response to: An example of the compiler not doing the right thing.
It's unlikely that Rust solves that better than C++ given how much effort there is behind C++ comparatively but who knows.
>#[inline(always)]
It exists on (virtually all) compilers, not as a language feature. But in C++ it's constraining the compiler to never break that code out into a function. Which is also harmful.

en.cppreference.com/w/c/io/getchar

Assuming this is user input from stdin (you type shit into the terminal) how would you tell it to end your input?

>C++
In all the mess of standard library iterators and streams, how the fuck do I just read a file containing a bunch of 32bit words into a std::vector? I can read into a char vector and reinterpret_cast, but that's shit.

>It's unlikely that Rust solves that better than C++ given how much effort there is behind C++ comparatively
This needs to be emphasized. Rust is very young and does not have even a tenth of the work that has gone into optimizing C++. Maybe in 2037 it will be as fast as C++ is today.

man 2 read

I chuckled

That's unportable C.

man 2 girl

>C
>unportable
what?

>implying reading 32bit words is readable in C

Is it a joke? Really?

So I noticed ctrl-d will end it, but it returns 1 higher than expected, is it counting ctrl-d as a character?

Sane, straightforward and most efficient way:

vector.reserve(size_of_file / 4)
uint32_t *p = vector.data()
read directly into p with fread() or filestream.read()
(assuming endianess of file data is same as system program is running on, and that they are all contiguous of course)

read() is in unistd.h which is unportable.
It is in C (I asked for C++) AND it is unportable. Not C is unportable.

it's unix c, not portable to nt

Difficult know. It's not the most normal way to do input to actually have the user use ctrl+d to terminate. Can't really help you. If you open your debugger or print the characters as they're input you might catch it. It shouldn't actually count the EOL since it breaks when it sees EOL.

No idea, it prints the correct amount of inserted characters for me.

ctl-d is the character '\004'
it is not EOF

Don't be rude user you're just causing confusion here.

what's the cleanest way to make this also record the nominations it uses? a tuple of an integer and a list of values for the number of coins used for each denomination? maybe it's just b/c i don't use tuples in python hardly at all but that seems a bit complicated

def makingChange(denoms, amount):
optimums = {}
optimums[0] = 0
optimums[1] = 1 # to make change for 1 cent, use a single 1 cent coin
for i in range(2, amount+1):
next = [i-x for x in denoms if i-x >= 0]
optimums[i] = min(map(lambda x: optimums[x], next)) + 1
return optimums[amount]

for i in range(1, 101):
print(i, " : ", makingChange([1,5,10,25], i))

How do I implement a json parser in C?
I mean, how would I deal with nested json subvalues of arbitrary depth?
This just seems like it would bloat up my parser a lot.

With a stack.

Technically EOF is platform specific.

Parsing JSON isn't trivial: seriot.ch/parsing_json.php

Yes. That's what I'm saying. It's not helping someone who's new to consider that right now.

No. Please that's a joke.

You use a json library instead of wasting your time.

because looking at it now it seems like i won't be able to do the list comprehension and lambda map if i want to also do that. that i would have to use loops

unstid.h is part of the Portable Operating System Interface.

Implementd by less than 1% of the computers.

Are you saying there are over 150 billion computers in the world?

Please
Help

Learning C. Am i going to run into problems switching between Linux and FreeBSD? Will binarys work as long as they're both compiled on x86?

It depends of what a computer is.

no i thought it was a good comment, at least I know the code sorta works,

GNU/Linux*

Well android accounts for 1.4 billion alone, so if that is

They are not binary compatible, but FreeBSD has a Linux emulation layer which works reasonably well, but if it's a panorama making use of new Linux-kernel specific stuff, it's probably not gonna work.

Ho shit I forgot the android "Linux". But they're not really computer.

Sure Android has builtin POSIX?

OTOH servers are overwhelmingly unices and if VMs count as computer then we're done arguing.

LibreOffice Writer

should be while ((getchar()) != EOF)

>>>/sqt/

Who cares about binary compatibility besides Jewish software vendors? My bytecode is source code, hacker at heart till death do us apart!

Bullshit. Don't listen to him, parens (except function call parens and if/while/for parens) are used to counter operaror priority. In this case, those are unnecessary

No, that'd be only true if you were assigning to a variable with getchar() inside of the while statement.

Well it should be or else winforms doesn't deserve the title of programming language, which I wouldn't know. Now fuck off.

The post is programming related, but because nobody can answer it, it belongs in sqt?
Fuck off pajeet

There is literally nothing wrong with being jewish.

>pajeet
pls no racism

Speaking of which, how does one ship binaries on Linux to make sure they run on various systems?
All of my libraries that I use are not GPL-cancer so I can statically link them, will that suffice given GLIBC major version on the target system is the same?

...

bwahah holy shit! the memes are real
youtube.com/watch?v=CRUa_09IOVU

Trash/Linux*

Well there's LLVM. Offsets a lot of that.

Now you have two problems.

Trash/systemd*

OOL NI OOP

How so?

youtube.com/watch?v=zPTY1hKq3SU

Please respond

I want to have a single game world state that's operated on by a lot of threads (client connections). I could probably queue up all actions that each client has taken (one queue per client), and then on each server tick, copy over those actions and calculate them then broadcast the new game world state to every client. Is there a better way to do this?

кoт

man youtube-dl

idea stolen. thanks! should be a fun weekend project