/dpt/ - Daily Programming Thread:

What are you working on, Sup Forums?
Previous thread:

Attached: 1521281839145.jpg (500x368, 24K)

Other urls found in this thread:

pastebin.com/7YwMhgj0
gitgud.io/n02/booruclient
pastebin.com/ca5E3RDy
pastebin.com/wuMkZARS
stackoverflow.com/questions/3922840/sfml-window-resizing-events-blocking-the-main-thread
en.cppreference.com/w/cpp/error/assert
twitter.com/SFWRedditImages

Why does the c++ environment suck so hard? It would be bad enough if you just had to deal with the language, but then you have to top it off with no good language dependency manager dozens of build systems, testing frameworks, etc. Its so hard to use other people's libraries sometimes it's easier to rewrite the code yourself than to even build the other guys library. And don't even get me started on cross compilation.

>the c++ environment
vi / vim?
codeblocks?
eclipse?

Autotools, cmake, makefiles, meson, premake, scons, waf, jam

help my program is ignore SIGKILL send help

write a signal handler that creates a new process

Any good x86 (i686, amd64) assembly books?

>cmake, makefiles
that's the only part you really need

Can anyone help me out here? I'm working on making a terminal UI thing in SFML and I can't even manage to just draw the background of the thing.
pastebin.com/7YwMhgj0
I'm not sure why a bunch of the rectangles are bunching up on the left and bottom instead of filling the whole screen.
It looks like the last row is somehow fucking up the ones above it but idk.

Attached: Untitled.png (722x440, 2K)

I have made a gui client for booru websites. and here it is: gitgud.io/n02/booruclient
Do you like my program?

Attached: 3798717.gif (540x612, 108K)

I wanna git gud at C#, anyone know where to start?

It would be if all my dependencies used cmake, but they dont.

Because you got the coordinates wrong, you're painting 24 squares sideways, not 80.

Learn to use CMake — it has tools specifically for this issue.

now I see all you guys posting about how comfy C is, and I really want to learn it desu, but what usecases are there for C? im a brainlet pls help

Attached: thinking.jpg (4752x3168, 2.5M)

Is this right?

>Write the function strend(s,t) which returns 1 if the string t occurs at the end of string s and 0 otherwise
int strend(char *s, char *t)
{
int i = strlen(t);
for ( ; *s; s++) ;
for ( ; *t; t++) ;
for ( ; i >= 0; --i, --s, --t) {
if (*s != *t) {
return 0;
}
}
return 1;
}

Attached: lain.jpg (239x239, 60K)

C is good when performance is your top priority.

C is extremely prevalent in open source software.
If you're doing anything with that, knowing (and using) C is a requirement.

size_t ns = strlen(s), nt = strlen(t);
return (ns >= nt) && !memcmp(s+ns-nt, t, nt);

Please rate my Python:

pastebin.com/ca5E3RDy

It's a basic C code generator.

Not really. In large programs, C tends to be rather slow because it's hard to take advantage of global program optimizations with it.

It is however very good for writing short programs that are callable from other languages, like Python extensions. For those cases, it has very little overhead, and it's faster and simpler than the other languages that would be faster when applied to a full program.

I love C. I first set the values of the array like array[n]=n. right after that, we have this piece:

printf("%d ",array[60] );

shuffle= rand()%SHUFFLEMETHODS;
printf("%d \n",array[60] );

First printf returns 60, second returns 0. What the fucka is going on?

>Not really. In large programs, C tends to be rather slow because it's hard to take advantage of global program optimizations with it.
Compilers have had link time optimisers for a while now. This argument is no longer true.
Even without that, the raw speed that C allows for is much more than basically every other language.

Post the whole program.

Right, let me reconfigure my psy-ray to figure out whatever the fuck is going on in the rest of your shitty program.

Thanks

It's still significantly worse at it than good Sepples, D, or Rust. And compared to C++, the lack of generics and overloading means that you can't write generic code that automatically selects the correct algorithms for given inputs, like automatically using radix sort instead of a comparison sort when sorting numbers. In real-life C programs you end up with a lot of void pointers everywhere.

The lack of compile time reflection means that many optimizations can be impossible to try out without rewriting your entire program. For example, changing a program from using arrays of structs to structs of arrays to try out an entity system requires changing the whole program. If you had compile time reflection, you can make a custom array type whose memory layout puts corresponding fields together.

The ability to change algorithms without changing the whole program so that you can benchmark possible optimizations is key to writing fast programs in practice rather than in theory, and C is terrible at it.

I've stripped all the uninteresting parts, and tested to see if it would still happen, and surprise, it still does.

#include
#include
#define SHUFFLEMETHODS 1

void riffle(int *array, int size){
//do shit
}
int main(){
int array[60], result[4], size=60,j,i,shuffle,cic;

for(i=1;i0;i--){
cic= 1+rand()%2;
while(cic){

//WTF??!!!
printf("%d ",array[60] );

shuffle= rand()%SHUFFLEMETHODS;
printf("%d \n",array[60] );

switch(shuffle){
case 0:
riffle(array,size);
break;
}
cic--;
}
result[i-1]=array[size];
size--;
}
for(i=0;i

You bring up all that shit, but C consistently beats other languages in almost every benchmark.
Sepples doesn't even have restrict pointers.

arrays are 0 indexed, so the valid values are array[0] through array[59]. array[60] is invalid.

Very cool. Nice work, user!

You really like iterators from the look of it. Looks well laid out and very nice user.

>doesn't know c arrays are zero-indexed
Time to read some more

>software I might actually use
>/dpt/
What's going on

>arrays are 0 indexed
Last year I completed all the challenges of advent of code in C. I should set myself on fire in a gas station

Attached: 1496193590815.gif (265x200, 1.96M)

it should be, the first two loops are unnecessary though, see below (untested, i also dislike for loops)
int strend(char *s, char *t)
{
int tlen = strlen(t);

s += strlen(s);
t += tlen;
while(*s == *t && tlen > 0) {
--tlen; --s; --t;
}
if(tlen == 0) {
return 1;
} else {
return 0;
}
}

shortened
int strend(char *s, char *t)
{
int tlen = strlen(t);

s += strlen(s);
t += tlen;
while(*s == *t && tlen) {
--tlen; --s; --t;
}
if(tlen)
return 1;
return 0;
}

>i also dislike for loops
That's fucking stupid.

fuck, it should be "if(!tlen)"
not really, if you are not using a variable within its scope, i dont see the point. this is good use:
>for(size_t i = 5; *array; --i, --array);

If you write software with the expectation that you don't have to debug anything or implement any of the features you obviously need, like most open source projects, then C is exactly the language for you! It will accept just about any source code that parses as legal syntax and gleefully Segmentation fault (core dumped)

Attached: legostep.gif (300x300, 777K)

>not really, if you are not using a variable within its scope, i dont see the point. this is good use:
Ok, I thought you were talking about for loops in general.

I'm writing code to drive my wrist mounted computer. I'll release source when done if anyone cares.

Attached: 20180324_114000_noexif.jpg (4032x3024, 2.76M)

T-thanks...
I'm sure you will like it user. I'll continue implementing features, probably tomorrow, I'm too tired now. You can add feature requests if you want.

>boot windows
>try to compile and run my project
>it shits the bed
now I remember why I gave up on trying to get it to work on Windows half a year ago, it's such a retarded issue that I've no idea how to debug

Thanks! I didn't have as many iterators eventually, but iterating over lines of C code turned out to be really convenient so I went with it.

Coming from Scheme I really missed lisp macros. My first instinct would be to go crazy with them to make a more declarative syntax, building expression trees imperatively in Python feels really low level. But I was planning to use this for a Python DSL in a personal project that I'll be putting up on my Github, so w/e.

>Because you got the coordinates wrong, you're painting 24 squares sideways, not 80.
But whatever the last row is it always paints 80 squares sideways. Pic related is when I only go 12 rows down.

Attached: Untitled.png (722x440, 2K)

Yes you're just indexing your shit wrong.

As said, fix your indexing.

Attached: Untitled.png (728x435, 8K)

what are you even doing that doesn't outright work?

got it now
Another thing I'm trying to figure out is how to keep the program working while resizing it in Windows. On Linux everything is great but on Windows and everything on the same thread it seems like resizing the window pauses it until the cursor is let go. I used the example of having a separate rendering thread to try and solve it and that stopped the program freezing during resize but the issue is I still can't detect the window size being changed until the cursor is let go. Any ideas?
pastebin.com/wuMkZARS

The microsoft textbook for c# is pretty good

Thanks, incrementing the pointers with strlen seems like a better practice

I'll just repost what I posted a couple months back.
So I have the following piece of C++ code:
static std::mutex Mutex;
static std::string LogFile;

void SetLogFile(const std::string &path)
{
LogFile = path;
}

void Log(const LogLevel &level, const char *format, const fmt::ArgList &args)
{
if (!LogFile.size()) {
std::cout

stackoverflow.com/questions/3922840/sfml-window-resizing-events-blocking-the-main-thread

Microbenchmarks =/= real world code.

C performs well on benchmarks because those don't depend on whole-program optimizations. C is very good at single functions, but when you start building bigger projects with it, you invariably end up with significant performance tradeoffs to make your code remotely usable, which you would not have had to do in C++ or any programming language with support for generic programming and proper zero cost abstractions.

Attached: 1393889235160.png (760x572, 247K)

there's no reason. the problem must be somewhere else.

rip

Attached: Untitled.png (534x422, 17K)

>makefiles
that's the only part you really need.

>Need to do assignment on Visual Basic
>Breeze through it
>Check instructions to make sure nothing's missing
>Need to include "A screen dump of an error bug you came across saved as a jpg file."
>tfw the whole thing was flawless without any errors

Attached: 1433130466484.jpg (1024x569, 109K)

so? the solution the commenter gave isn't so complex you need to copy their code like a pajeet

Remove a semicolon at the end and take a picture.
The solution the commenter gave was literally what I've already come up with and posted. I've already found how to stop blocking the main thread. What I need is how to detect window resizes before the cursor is let go.

Oh yeah I actually hooked up a debugger now and remembered that I in fact found the issue back then and forgot about it. It's because LuaJIT doesn't work with 64-bit MinGW.

>global program optimizations
What language do you suggest does this well? I heard Intels compiler tries to do this for C and C++ but the results are lacking compared to other methods so it'd be interesting to know just what language features simplify this.

Every time I do an assignment there's a section in the writeup of "Errors you came across"
Which is "Fucking nothing" because I do test driven development and these projects are too tiny for weird things to crop up

>In large programs, C tends to be rather slow
u wot nigger

>screenshot of a text editor GUI
>flat rectangles, barely-antialiased text, mabye a couple of different distinct pixel colors total combined
>saved as JPG
It's a trick question.

>sepples does better
For global program optimization it's in the exact same seat though. I can't think of a single C++ construct that'd aid this.
Please show some example.
>in real life C you end up with void pointers
Not accurate to my experience but I'd like you to give examples.
>you can't write generic code that automatically selects the right algorithm given inputs
That's why you) we do metaprogramming. For this use case it's a rather obscure situation and it's absolutely not something you even want for the normal tasks C is faced with. Seems more like you're trying to use C as some kind of scripting language if you didn't want a very obvious code execution.
>compile time reflection
Yeah that's missed. But again, metaprogramming isn't really solved in any of the alternatives. They always give you weak bullshit or terrible interface so you're stuck with writing your own metaprogramming library. Which really isn't difficult for a simple language like C.
>SOA vs AoS
This really is part of the overall lack of respect people have for effective memory use. How bizarre is it that I don't know of a single language that actually gives you explicit control of struct packing or even the option to give it up to the compiler fully. It's such an obvious feature to add to a language. Compilers aren't even required to implement it beyond a noop keyword (for instance) if they didn't want it so it's free.
>change algorithms effectively without changing the program
I can't think of a language that does this meaningfully.
Algorithms and datastructures are closely tied as we all know.
If we have a set of algorithms to apply the problem of effectively combining these for any type of datastructure absolutely seems to boil down to writing them all explicitly.
>performance tradeoffs to make your code remotely usable
What? Free function calls is one of the most cheap interfaces available since basically all

>since basically all
Abstractions rely on something like this. Most anyway.
>change algorithms without changing the program
I think maybe I should clarify.
Anyone who has written optimized code knows that you can't consider your transformations separate at all in the end. Even if you're in the lucky situation of being able to break out each transformation into separate functions at no cost to the number of instructions, just the act of doing multiple iterations is problematic. And in the generic case of arbitrary datastructures that gets more complicated to manage.
And say you've got completely separate iteration orders so you'd think you couldn't somehow combine operations you're still going to miss out on basic optimizations for tons of algorithms. Like for instance if you were to want a pivot at any time in the program you might want to work out where that should be during some other iteration of the data. And that's probably the simplest case I can think of because it's just a placement and value gather. Doesn't need a full iteration to be helpful even.
The generic code that does this for all relevant algorithms and datastructures must be incredibly complex. You'd mark up context like how this algorithm doesn't/does mutate the data, or maybe in a specific pattern. You'd have to give context for what kind of precompute steps are possible in each step of the program and to what accuracy.
It's just an incredibly complex problem which boils down to automating the programmer himself. Because when you have this system and an interface, what you've written is a problem description language and an algorithm optimizer.
I would really like to think I'd know of a language that does this if it does this. It's the second best thing to having an AI write this program for you.
That way it could improve it. I wouldn't trust a human to do that really.

all arrays are indexed.
Any language that does it another way is fucking retarded.

>kiddies count from 1 -> INF
>adults count from 0 -> INF

>wrist mounted computer
wounds pretty cool, is it /hard/ or did you just grab the nearest RPI and settle on that?

Regardless its pretty cool, is it useful or do you just settle on it being cool?

>0 index vs 1 index
It's just a matter of what you're abstracting. 0 index is for memory 1 index can be for element position.
N-index can be for something more complicated.

working on a script to automate the login & usage of a website which gives a plaintxt output. Basically just breaking their "security" for the login

0 index is for everything fampai, not jsut memory.

When the teller asks for 10 dollars, i pay 9 because 9 + 0 = 10

Attached: 2682997.gif (177x180, 756K)

Look at these little babies trying to be clever. Arrays aren't going to stop working the way they work just because programmers stop knowing what an array actually is.

desu, if i ever make a language it will be 1 index'd.
We had it right way back then but somehow lost our way with C and the dumb gnome forgot to keep it from algol.

>What are you working on, Sup Forums?
Working on some more filters for my image glitching script. Found out that you should not have two shaders programs trying to output to the same fbo on the same pixels at the same time or else you get artifacts.

Attached: scrot.png (1920x1080, 436K)

> tfw quit job
> Look at org mode
> Think "ohh, there's a good way to organize all my time so I will be productive "
> 6 months later I am still a Neet but have become the maintainer of an obscure language's emacs package

How deep does the rabbit hole go?

why are there so many furfags in Sup Forums?

Attached: ItalianBobcat.jpg (403x649, 98K)

>How deep does the rabbit hole go?
you developing your own CPU + OS + programming language ecosystem.

Man, I really feel sorry for Terry.

Why?
He's just a mentally ill normie.

just use it to make things

Not a normie, no.

>he actually wants one extra CPU instruction every time he accesses an array member

>lusts for 3d
he's a normie.

>one extra CPU instruction
Oh no, how will i ever make anything now.
You act like that's the only thing that has instruction bloat.

sublime text + cmake

As often as moving through an array is done it's probably better to not do that everytime

>let's waste power for no reason at all

Can you really argue with fortran and cobol, considering actual real time-systems ran on them.

>a language isn't allowed to try to fix the errors of its predecessors
w e w

Use selenium to register a user big boiee

>error
eh, it's whatever. You'll always say that extra cycle will matter, even though it won't until you get into stupidly large use-cases that next to no one will actually have.

I'm recreating the C function strpbrk, my expected output should be a pointer to the letter 'i' in the statement "This is a string" using the key "aeiou".
Instead I am getting no output, would anyone care to explain why?
Thank you for your time.
char * mystrpbrk (const char *str1, const char *str2){

int i = 0;
int j = 0;

char *ptr1 = (char*) str1;
char *ptr2 = (char*) str2;

while(ptr1[i]){

while(ptr2[j]){

if(ptr1[i] == ptr2[j]){
return &ptr1[i];
}
j++;
}
i++;
}
return NULL;
}

you don't reset j to zero after the inner loop
declare that shit under while(ptr1[i]) and it will do it automatically (scope), or set it to zero before i++

Ahh, a valuable lesson in scope and reset, thank you, my friend, she's working like a beaut now.

If i want to disable my asserts everywhere in my C++ program, do i need to add #define NDEBUG to every header file with assert included? Or can I just add it in one place.

Or should I just use compiler flag to disable it?

Does sepples not disable them in release mode?

en.cppreference.com/w/cpp/error/assert
You can define symbols with the -D flag to clang & gcc

C++ doesn't have a debug/release mode as part of the language

wow

I know, soyboys are so used to languages placing environment restrictions on them they don't appreciate it when a language gives them the choice to do things however they want.