/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Attached: prog.jpg (473x496, 105K)

Other urls found in this thread:

en.m.wikipedia.org/wiki/Vulkan_(API)
en.cppreference.com/w/cpp/language/alignas
drdobbs.com/cpp/cs-new-ease-of-use-and-how-the-language/240001401
en.cppreference.com/w/c/keyword/_Alignas
en.cppreference.com/w/c/keyword/_Alignof
github.com/timotheecour/D_vs_nim
twitter.com/NSFWRedditVideo

Nothing.

fuck opengl

It's not a real fork bomb. Unbounded recursion will overflow the stack, except in the case of recursive calls to main(), which is undefined behavior. Now, any sensible compiler (when compiling with -O2 or higher, which any C programmer will always do) will transform the tail call into a loop and observe via dead code analysis that main() never returns. It should emit a warning for this but that's okay. The loop, consisting of 2**n calls to fork(), will be further reduced through vectorization (which of course you've turned on in your compiler flags), transformed into an expression, and inlined into _start().
Note the type signature. The compiler knows at this point that main() doesn't use the command line arguments, and also that the whole function is a noop and is never actually called. Normally it would go ahead and generate it anyway, but because of the recursive call, we've already invoked undefined behavior. The result of the call to fork(), which is never used and normally would be removed altogether, allocates space on the stack in _start() for a pid_t. As you know, this is a signed integer type, so by overflowing it with 2**n calls to fork(), we hit further undefined behavior.
This is the clever part. The compiled program will reuse existing memory containing its command line arguments and then allocate space in _start() for the vectorized expression using the characters (ie. the digits encoded in ASCII) as the starting value. For obvious reasons (I assume you know your trig identities by heart) the space consumed is equivalent to the sum of these digits in base 10. The argument to brk() will be left in a register, so the OS will return an error during the call to fork(). A little bit of return-oriented programming later, the result will be printed to stderr, the program will exit, and Bob's your uncle.

Attached: 1465848587384.png (1280x1707, 1.81M)

Should be working on a better object scheme so that I'm not doing sample calculation on my mixing thread, but instead I'm wasting my life watching Naruto like a weaboo fag

this

>not using Vulkan
2 slo gramps

yeah fuck device support

def digitSum(n: Int): Int = n match {
case 0 => 0
case n => n%10 + digitSum(n/10)
}

No sense in using an accumulator if you're working with under 40/70 stack frames anyway.

I am learning Python.
I am using Visual Studio Code as my IDE, with the Microsoft Python Extension installed.

I am having some problems with the intellisense. It doesn't always list all of the available members of an object.

>except in the case of recursive calls to main(), which is undefined behavior
How is a recursive call to main() undefined behavior?

Let's be honest: do most people here actually use the device support? (At least more than is listed here: en.m.wikipedia.org/wiki/Vulkan_(API) )

Enjoy your slow code that will smash the stack if you port it to big int. Mine is faster, safer and will work with big int.

Gee, Dr. Smoothbrain, maybe you should read the C standard like an adult. Then you'd know that calling main() from any function is UB.

What lang is this?

I have, and I just searched it as a reference, and I can't find any clause in there marking it as undefined behavior. Can you give a reference as to where exactly it says that?

So you're telling me that this will do everything you said and produce the expected output?
main:
sub rsp, 8
.L2:
call fork
jmp .L2

picrel

Attached: CAQi-bOUwAAUPQ3 hascalator.jpg (768x1024, 92K)

>overengineering fizzbuzz
thank you for your time

Related to this: I went to an audio programming job interview recently and one of the interviewers hinted at viewing the signal flow of realtime audio processing as a graph which is then decomposed into a series of function calls (implying that there is no concept of a "mixer object"). Is this the preferred method of realtime audio architecture or was this just some mixed signals I was getting? Perhaps they're working in straight C and they don't have the luxury of objects?

My code overengineered? You must be trolling. I hope your trolling. You're trolling, aren't you?

>trolling
hi tumblr we dont use that word anymore in current year

ok

lmao

You're the one who needs to read the standard, idiot.
Calling main() is completely fine in C.

american pancakes always look so gross

Not him but main is special in C++, it inherits from C so probably the same

Anybody here that has released a game before?

It has the same role in C, but calling it recursively is entirely allowed.

Half-half.
As this is freshman homework level code, one would normally just write out both versions, or throw in a comment re pros/cons of adding accumulators.
Depends whether the focus of whatever lecture this is attached to is babby's first recursion, or recursion with perf not totally ignored.
Clean/elegant vs efficient - assuming TCO, of course.

gotta keep the bantz up
the moment you start taking yourself too srsly, shit's goin' downhill

omg which one is it, should you have a space after new in placement new or not
not having a space is more clear?

alignas(int) char storage[sizeof(int)];
int *ptr = new(storage) int;
*ptr = 0;
cout

Even better, don't use placement new. Or constructors. Or C++.

ebin le maymay

Only student projects here, but I exhibited at PAX if that's any consolation

I'm telling you, it's not worth diving into this rabbit hole. There's no light, only darkness.

>alignas
>non-american language keywords
what kind of discount proglang is this

it's fucking nice in its full context and really straightforward except for this tiny little style issue where stackoverflow answers circa 2011 did it like new (storage) int but now new(storage) int seems to be the more common style

meh, just wanted to see what someone else has published

>align as

>Update Nuget Package
>Solution wont compile anymore
>The package edited files not part of the package when it updates
>Fix them
>No errors
>Build
>Suddenly errors
>google them
>'most likely it means your compiler is corrupt, must reinstall'
I guess this is what I get for using microshit. How many languages/IDEs are so retarded that you can corrupt your compiler by updating a library?

yes, just like dignit as, and whatever other ass words those damn special snowflake forriners got

Attached: dpt.jpg (1200x683, 192K)

git gud

Attached: 1521345175090.jpg (701x394, 47K)

jelly of our world dominance?

en.cppreference.com/w/cpp/language/alignas
(You)

>dignitas

>when you see the waffle looks like a keyboard

that's a waffle with puke on

I don't need no damn dictionaries, programming codes are meant to be written in american

I hope you don't like C then

C is a proper American language, not made by some surrender monkeys or nazi hasbeens like whatever that guy posted.

drdobbs.com/cpp/cs-new-ease-of-use-and-how-the-language/240001401

You were saying?
en.cppreference.com/w/c/keyword/_Alignas
en.cppreference.com/w/c/keyword/_Alignof

*laughs in chinese*

Attached: 540749687d808.jpg (800x480, 234K)

>malloc

get your yuroqueer propaganda outta here
I don't like em latinos, why do you think russkis are any better?

Webdev here from /wdg/. I need to learn data structures to build better projects with my JavaScript. What are the best resources for teaching data structures /dpt/?

>first thing to come to mind is the team instead of the project
gb2veee

C and C++ are different languages, idiot.
It's valid in C, invalid in C++.

>placement new
lets you have arrays without default-constructing objects, useful when you don't need a resizeable std::vector (vectors also use placement new under the hood)
lets you have objects that are fully immutable across their lifespan, can be useful in many ways

OYU GUYS

Is there any ways to write a program/script that will grab keyboard input whether you're focused on the program's window or not.

For example, the Program X is running & waiting for input but windows focus is on program Y, if I press "K" while focused on Y,code from X runs.

I don't give a shit what language or framework I need to use, I need this functionality bad.

then why is one literally called the same as the other
that's like saying notepad++ is not an improved *version* of notepad

>We empower teachers and transform schools in Kenya
did you mean project veritas

So basically when you use a placement new the memory for the object will be allocated but the constructor will not be called? Is there something like placement delete as well? Where you'd delete the occupied memory but not call the destructor?

the term you're looking for is "global hotkeys"

>Download OST of a JRPG
>Unzipping broke the filenames because of moonrunes
>Mp3 tags still contain the titles, unbroken
>Search for tools to rename files from the ID3 tags
>Find id3ren
>It being written in C, so it doesn't handle non-ascii filenames correctly
>Filenames still broken
>Write my own tool in Rust

It not only worked, it even handles glob matching (e.g. tag-to-filename *.mp3 renames all .mp3s from their tags), all in little more than 100 lines. It's sloppily made and not very flexible atm, but it's at least usable for non-ascii filenames unlike id3ren. Made me a bit happy desu.

Attached: 1504347644171.jpg (696x720, 30K)

>not being aware of the organization
talk about sheltered gaymanchildren

It's the other way around. It invokes the constructor but without allocating.
You can call the destructor without deallocating also.
myobj->~MyType();

I wish more languages had polymorphic variants.

>tfw I have a whole bunch of broken fonts like this I downloaded years ago and still haven't bothered fixing

>reinvent wheel IN RUST cuz too lazy to use non-shit filesystem
typical rustlets

the memory is allocated in advance without calling the constructor. then you call the constructor and specify a pointer to where to store the object
you call the destructor if necessary and then you can free the allocated memory

{ +[](void *here, void const *other){ new (here) T( *(T const*) other); } };

the power of sepples, the power of placement new

i fcukin love you

>implying filenames need anything more than ASCII

What would someone be like if haskell were their first language? And only later they discovered that mutation was possible. Would they hate every language?

Attached: bane.jpg (625x390, 86K)

tfw I have files with moonrunes on my linux but when I send it to my android it's s̷̨̨̜̝̖̫͍͓̟̈͗ȍ̷̻͇̻͉͎͈̫̉̐̔m͉̩̺̺͍͙̪̬̽͛̈́̂̊̆͛͟e̦̥̘̘̭̞̖̍́ ̠̣̼̹̖̒ͮ̐̚ų̨͎̠̌̄̽̑͋̇n̦̘͖͍ͧ͗͂͋ͩr̵̗̫̪̯͉̾͛ͅͅẽ̸̶͔̻͚̺̳̫ͩ̑̽́̚a̖̱͇͌̈ḑ̖̰̠̯ͯ͆̍͌̑͋̾̄ą̦̯ͧ̃̈̔̀ͅb͈̐̀ͤͧ͆̇ͦ̄͘l̜̠̩̤̫͓ͤ̿̏̆̋̔̋̋ͅe̴̛̹̓ͧ̈́ͣͯ̑ ̨͙̍ͭͬͬ̒͛̓͡s̨͉̓h̸̛͇̣͔͖̯͚̔͑i̞̻̓̃̏͋ṭ̨͈̤̐̓
any ideas how to fix it?

Attached: 1514288970536.png (783x810, 965K)

shut up bby, i knowit

Rewriting is always the wrong answer. You should have fixed the original project and sent them a patch.

Has nothing to do with the filesytem, unzipping used the wrong encoding.

Pic related, left how it was before, right after my fix.

Attached: 1502013833719.png (1920x1080, 224K)

Attached: 1521369552824.jpg (342x342, 50K)

Most C programs don't give a crap about filename encoding, and will just pass everything through transparently.
It only matters on shit OSs (winmeme) where the filenames are encoded in a retarded way.

template
constexpr
std::array getMoveCtors()
{
std::array result =
{ +[](void *here, void *other){ new (here) T(std::move(*(T*) other)); } };

if constexpr (0 < sizeof... (Ts))
{
std::array rest = getMoveCtors();
for (size_t i = 0; i < sizeof... (Ts); ++i)
result[i+1] = rest[i];
}

return result;
}

such beautiful code

i'm so glad I have constructors instead of init functions

remove moonrunes
reference:

github.com/timotheecour/D_vs_nim

Nim vs D.

>near
>far
>wherever you are
sepples dion is pretty decent desu

>no littered auto's everywhere
not modern sepples / 10

>i wish more language supported if-based polymorphism

ur but vs my D

t. english only brainlets

Attached: alicja.jpg (1000x1000, 193K)

>this code compiles
the state of sepples

struct lmao
{
lmao() = delete;
};

lmao bar{};

They're both shit, use Zig

Attached: Zig is on track..png (1110x166, 19K)

literally 3 seconds in and the nim bias is way too apparent.
>all those irrelevant subjective points
awful

/dpt/ already hates every language. most people here probably started with python or c or some shit like that

Polymorphism without indirection is valuable. More levels of indirection solves every problem except for too many levels of indirection.

Attached: brainlet.png (235x215, 5K)

t. code monkey writing comments in snowflake language

>Polymorphism without indirection is valuable
My point is that basically every language has that kind of "polymorphism", possibly minus some syntax sugar and type safety.

>snowflake language

Attached: oh you.jpg (400x400, 85K)