/dpt/ - Daily Programming Thread:

Old thread: What are you working on, Jow Forums?

Attached: YUNO.png (553x493, 50K)

Other urls found in this thread:

open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1152r3.html
blog.tartanllama.xyz/spaceship-operator/
youtube.com/watch?v=oBHbnxi-XVk
jobs.perl.org/
twitter.com/AnonBabble

I need to learn C (again)

Attached: 1554237281662.png (1920x2160, 2.04M)

I'm going back to programming in my homemade lang. Dealing with the issues that come with other langs is not worth it.

C is the best.

C++20 is cute.

half of C++20's additions are shit

What languages do I compile to SPIR-V?

Remember kids: do not, and I can't stress this enough, program videogames professionally.

you mean work for the AAA

Gonna hook up a C64 as a dumb terminal to a Raspberry Pi. I'm learning a ton about serial ports and transfer protocols from it, as well as C++.
Feels pretty good

Literally name 1 (one).

HLSL, GLSL? idk

Hello guys. I started to learn C a couple months ago and am confused about pointers and memory allocation. I know when you Malloc something it goes into the heap where u can use pointers to retrieve the info and then ur supposed to free the heap. But my question is that how do you guys know what’s what when you start getting pointers to pointers like arrays and shit without getting seg faulted? Sorry if this is an easy subject for you, but I have never worked with memory allocation before. I truly appreciate someone taking their time to help me. Thanks!!!

Lisp is the most powerful programming language.

Is there a way to format vscod(ium) to show in one column some C code and in the other the results of the assembly code? I want to know how compilers implement loops and if blocks.

>u
>ur
Please type properly.

>Thanks!!!
You're welcome!

>I started to learn C

C is garbage that forces programs to be more complex than they need to be by its very nature and yes the language is very verbose
unsigned long long int *foo;

uint64_t *foo

Make sure to initialize all your pointers to NULL so you can use conditionals to know where to stop. Use "calloc" if needed.
Double pointers are typically used on tables (arrays of arrays) or linked lists so it wouldn't harm to make the last element of them NULL so you can make simple checks while checking their contents.

typedef uint64_t u64;

the spaceship operator is overengineered garbage, and so are ranges
also contracts might not make it in, LOL

>how do you guys know what’s what when you start getting pointers to pointers like arrays and shit without getting seg faulted?

For starters I identify as an Apache attack helicopter, not a "guy", so please check your privileged.

Secondly what is so confusing about a pointer to a a pointer? Do you need a picture?

Attached: Double-Pointer-in-C.png (800x397, 44K)

gay faggot

i think what she's trying to ask is how to determine array bounds
the answer to which is "there is no language-supported way to determine array bounds, you as a programmer just have to never make a mistake or typo or off-by-1 error or you risk segfaulting or introducing security bugs"

How can you forget C, there's only like... 20 keywords.

It takes longer for me to deal with makefiles than to program

eh the spaceship operator reduces a lot of boilerplate in some cases

Attached: niggastolemybike.png (433x509, 257K)

Can you recommend some good open-source machine learning library (C, C++, Python, JS, Haskell, whatever) for a newbie?

idk why people hate on c++ so much. i'm finding it very fun so far. maybe the downsides become more noticeable when i learn lisp?

>spaceship
It's an old idea used in every nonmeme language. It's pretty neat, it simplifies code.

>ranges
Literal generic simplification to get away from iterator pairs. If you used boost or, hell, even C# long enough, ranges should be a natural concept to you.

Couple of popular recent blogposts about and ranges don't do these features justice. I understand authors wish to talk about inner mechanisms and complexity though.

>contracts
Yep, it's dead, Jim.

Attached: c++2x.jpg (800x1041, 248K)

keras

>deprecating volatile
what? It's literally necessary for any embedded programming where hardware needs signals or updates values silently

thanks user

Sepples is heaven compared to sea.
&((int*)m->thing->stuff.AAAAAAA[42])

Not well-versed in embedded shenanigans user, sorry.

Look for yourself open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1152r3.html

>The proposed deprecation preserves the useful parts of volatile, and removes the dubious / already broken ones.
Idk

Workin my way through this bad boy trying to get good enough to not be useless at my new job. Scala is pretty cool, especially coming from C#.

Attached: 41C+oHAw-fL._SX397_BO1,204,203,200_.jpg (399x499, 17K)

Why would anyone use Scala when Kotlin exists?

Wait wut, how can you get away with that? Even high level langs like Java have volatile.

>Computers are too hard for me

seems like the important C volatile stuff is preserved but they're getting rid of stupid C++ shit like volatile methods and template parameters

Attached: .png (825x550, 43K)

My sea works just fine. It's just an ugly ass language that overcomplicates things.

>SDE internship has been extended from the summer to part time during my last year at Uni and was basically told I have a job post grad if I want it
>born a poorfag so for the first time in my life have financial security

Attached: hugsnotdrugs.jpg (490x451, 22K)

I think they're trying to standardize what it means in multi-threaded/time-dependent environments. An example they give is an increment operation. Technically it likely involves a read-increment-store operation, which is implementation defined (the value could change if it's multiple operations).

They're not necessarily getting rid of it, but C++ has a lot more wrangling to do than C's "the compiler doesn't attempt to optimize operations on the data."

Please use Perl 5 for your next project!

Attached: 1478319843654.png (253x247, 98K)

Congrats user, be sure to build up a bunch of debt or else you might lose that eagerness and motivation to work for somebody else!

>C
>overcomplicates things

Attached: 1564742785811.png (1080x385, 38K)

i will not

Don't worry, I started accumulating educational debt years ago!

Woah, Anone! This JavaScript thing is so interesting! Please tell me more about it!

Attached: ceeb147c26c36aa99316b2ceaa97782b.jpg (600x900, 94K)

Don't forget blog.tartanllama.xyz/spaceship-operator/

>But my question is that how do you guys know what’s what when you start getting pointers to pointers like arrays and shit without getting seg faulted?
Resource management gets difficult if you're not rigorous. You build a system and make sure you know who's supposed to handle the memory. But it's one of the more difficult things to deal with with the most typical way new people write programs. It's why RAII in C++ is so popular. The best advice I can give is that whenever you type malloc into your program immediately note down or write into the program when free is supposed to be called. Maybe what you malloc needs to be passed out of the function, then you can't exactly know where to write your free. It's the callers responsibility. Then you should note that for yourself so you don't forget.
If you want to have a safety net you can get a memory leak detector. They usually point you to the line and file where the allocation that leaked happened. Then you figure out why it wasn't freed. Sometimes it can get hard.

The idea is fine, the implementation is way more complex than it needs to be.
Same with ranges, although that could have been improved considerably if they just implemented an |> operator
Contracts was the only one of these that seemed sensible, why did they ditch it?

First for Erlang

Attached: 1562427308623.jpg (500x529, 47K)

i thought you were the one teaching the javascript lessons

I miss Joe

Second for Common Lisp

how is pronounced "Anone" ?

Why not, user?

Attached: 1525550619595.png (1278x720, 765K)

Why would anyone use Scala when Haskell exists?

i pronounce it user-eh

why would i, perl seems like write-only abandoned language that's good for golfing only

Why would anyone use [jvm language that is not Clojure] when Clojure exists?

i prefer languages that i can actually read after writing

Perl can be written in a maintainable and understandable if you just try, Anons!

Bad programmers write bad code, and Perl gives them the extra flexibility needed to write terrible code.

>back and forth operator
>overcomplicates
do all cniles have a 2digit IQ?

but i am a bad programmer

why would anyone waste time programming when they can just have sex with (barely legal) teens all day long?

I'm sorry your brain is small, user.

Sorry about that! I will make sure to type properly next time I post.
I should of clarified better. I started learning it around January and kind of forgot so I am reteaching myself.
>calloc
So calloc just allocates the size but sets all bytes to zero? I'm surprised I didn't read anything about this before, my bad. Traversing linked lists usually isn't a problem but it seems like arrays are more of a difficult thing for me for some reason. I appreciate this a lot.
Thank you for the picture and sorry for misgendering you. I am truly sorry.
Thank you for the tips. I am pretty new to low-level programming. I think I am pretty stupid to just not right it down like a normal person. Sometimes I use gdb for it but I feel just noting to myself when I call malloc/calloc would be more helpful in the long run. Thanks!!!

"Anoun"

A lot of companies pay good cobol-style money for perl tbqh, there was a /dpt/ eu boomer who told us that.

>should of
die

youtube.com/watch?v=oBHbnxi-XVk

>no types
>subroutines

post your code

based Perl coming through

Attached: ll.png (1366x768, 231K)

that's "ano ne". they're two distinct words.

cutiepie

Attached: 1545519522572.gif (500x250, 825K)

Yes but it's what I thought of when I read anone.
So the rest of you don't have any say in the matter anymore. Sorry.

autism

Gamedevs complained about operator returning a library type std::strong_ordering. They don't use stl

auto operator(x const&) = default;
hot

can't you just slap this somewhere:
namespace std {
struct strong_ordering {
using less = 0;
using equivalent = 1;
using equal = 2;
using greater = 3;
};
// operators
}

namespace std {
//actually writing something in here when you're not a compiler programmer
}

It's a bad idea.

I compiled this program I found online.

Now to find out how it works.

Attached: Screenshot from 2019-08-04 17-22-05.png (1024x805, 41K)

>objectifying your Perl
I miss writing Perl. I WISH I HAD A JOB

Attached: wew.png (1235x744, 55K)

why do you care about incel opinions

can't you apply for a job?

I want a dolly.

Attached: s-l640.jpg (453x640, 55K)

>gamedevs
>incel
Oh come on user they're as progressive as the rest of the indu-
>pic

Attached: file.png (595x1032, 99K)

Unless you're specialising templates of course.

I haven't used it in like 7 years and even then I wasn't proficient in it
I don't know what to practice on

Attached: 1540694978690.jpg (639x629, 61K)

I have. I'm kinda broken now. Getting higher dose of meds and other treatment soon. :ok_fingers_emoji:

package EnvModule;

use strict;
use warnings;

#use Exporter qw(import);

#our @EXPORT_OK = qw/read write/;

&main;

sub main{

my $hashref = "";

$hashref = &read;

make_environment_bat($hashref);

exit 0;
}


sub read{
my @environment = `set`;
my $line = "";
my %environmenthash = ();

foreach $line (@environment){
if( $line =~ m/(.*)(?: )?=(?: )?(.*)/ ){
$environmenthash{$1} = $2;
}
}
return \%environmenthash;
}

sub make_environment_bat{
my ($hashref) = @_;

my $outstring = "";
my $line = "";
my $bat = ".\\export_old_environment.bat";

$outstring .= "\@echo off\n";

foreach $line (sort keys%$hashref){
$outstring .= "set $line=\n";
}

foreach $line (sort keys%$hashref){
$outstring .= "set $line=$hashref->{$line}\n"; #$line does not include the newline
}

#$outstring .= "exit /B 0\n";

open(OUTBAT, ">", $bat) or die "Could not open outbat for writing";
print OUTBAT $outstring;
close OUTBAT;
}

1;

If you're storing environment variables on Windows, they are case-sensitive! On GNU+Linux they are not. Perl always uppercases all environment variables, which breaks a bunch of shit if you're trying to save/load environment variables.

At work this mattered because we used different compilers and stuff, and I wanted to store the record of what we used during compilation.

incel isn't the opposite of progressive you fat nigger faggot

so I'm working with sockets on Unix and trying to make it so that I have a server running on one machine, a client on another, and they can both communicate with each other.

Everything works fine when I just use localhost (of course), but even when trying to connect to something on my home network (for example, my computer running the client to my raspberry pi running the server), I keep getting a 111 "connection refused" error.

Server:
int sock = socket(AF_INET, SOCK_STREAM, 0);

unsigned int port;
printf("Please enter a port: ");
scanf("%d", &port);

struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_port = htons(port);
address.sin_addr.s_addr = INADDR_ANY;

if (bind(sock, (struct sockaddr* ) &address, sin_size) < 0) {
printf("Error binding socket.\n");
exit(1);
}
printf("Bound\n");


Client:
int sock = socket(AF_INET, SOCK_STREAM, 0);

char server_ip[INET_ADDRSTRLEN];
printf("Enter Server IP address: ");
scanf("%s", server_ip);

unsigned short port;
printf("Enter Server port: ");
scanf("%d", &port);

struct sockaddr_in address;
address.sin_family = AF_INET;
address.sin_port = htons(port);
inet_ntop(AF_INET, &address.sin_addr, server_ip, INET_ADDRSTRLEN);

if (connect(sock, (struct sockaddr* ) &address, sizeof(address)) < 0) {
printf("Could not connect to server (%d).\n", errno);
exit(1);
}
printf("Connected.\n");


Could it be the INADDR_ANY in the server code? Is there any syscall or something to get your global / local IP address from, say, ifconfig?

>opposite
I never implied it.

then fuck off to Jow Forums with your retarded off-topic posting

>then fuck off
So it'd be fine if I did say it was the opposite?
Stop engaging with off topic posts.

damn
how do sustain yourself? do you ever got a job as a programmer?

just look it up there are some Perl jobs

jobs.perl.org/

Why are you using C for this? Seems like you're putting yourself through more pain than you need to.

I'd look at the network first. It's standard procedure for a network device that any incoming message on a port not established is refused unless forwarding is enabled/that service turned off. Additionally, this can be done at the OS level, where they block traffic on certain ports unless an outgoing message on that port was sent first.

Well done, user.

Attached: congrats.jpg (450x375, 63K)

I'm dependent on a parent. That website looks nice, though of course they want a lot of senior devs / not in US.