/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

en.wikipedia.org/wiki/C10k_problem
blog.reverberate.org/2013/08/parsing-c-is-literally-undecidable.html
twitter.com/SFWRedditImages

You made this thread one post too early

No because OP must post link to new thread. Get fucked, animushit.

No you fucking idiot, you don't make the thread at 309 and then post the 310th image, you don't make the thread until the old thread is at the bump limit (and even then, better if it's at page 10)

what level of newfaggotry is this

People were requesting a new thread already.

That's where you're wrong, kiddo.

>one person complained about anime in the thread

Well then make another thread already now that the last one finally is at bump limit and report this one, you fucking fag!

...

Girl *Hime = (Girl*)malloc(sizeof(Boy));

>What are you working on, Sup Forums?
Working on getting a hd44780 to work with a attiny13 and 74hc595 shift registers.
It does work SOMETIMES, but there seems to be some errors, sometimes. I guess it's some timing shit, but will see.

>Programming Challenges by Skiena
The video lectures for that book is hilarious.

Everybody can tell you're just trying to get OP to wait till the very last minute just so you can get a bigger shot of squeezing your shitty animu picture thread in before his, you fag.

l-lewd!

use std::mem::transmute as crossdress;

struct Boy;
struct Girl;

fn main() {
let Hime: Girl = unsafe { crossdress(Boy) };
}

bust

JUST

Programming is gay.

Why do so many people shit on C++? The performance difference between it and C is widely negligible (and often nonexistent), and has been with compilers in the last 5 years.

C is only more widely used as a systems language now because of existing codebases. Writing production C code is mind numbing compared to C++

What are some of the best most escential plugins for Vim or Nvim if I only program in C?

Because it's a disgustingly bloated and ambiguous language.

struct{
T* foo = NULL;
}bar;

void A(){
if(bar.foo == NULL)
bar.foo = new T[n];
else
ClearMemory();
//things

Z();
}

void Z(){
//things..
ClearMemory();
}

void ClearMemory(){
if(foo != NULL)
delete[] bar.foo;
bar.foo = NULL;
}

can somebody tell me why my program crashes at delete[]bar.foo after verifying that it isn't NULL

what the fuck does this even mean? Give me examples

Parsing C++ is undecidable.

Because you're using NULL in C++ code

uhh, where's the fucking anime image?

I want to like rust but there is just too many things wrong with it.

>devs of the language tell you to spawn a thread per socket connection
havent they heard of en.wikipedia.org/wiki/C10k_problem

anime technology is sexist you shitlord

I don't think there error is in what you posted, unless the first //things is supposed to be part of the else block and isn't in brackets. It might be null but idk

for the future, use descriptive names for foo and bar, and use C++11 nullptr instead of NULL

set softtabstop=2
set expandtab

>spawn a thread per socket connection
Where do they say that?

Can someone post the picture of the anime chick with orange/yellow hair and holding K&R?

...

You're the best.
I guess i remember the picture wrong, but this was it.

what?

blog.reverberate.org/2013/08/parsing-c-is-literally-undecidable.html

Okay, posting this again, since I'm home now and didn't get to see more replies.

What's the difference between a void method and a non-void method? What eaxctly does return do?

static void test(int a, int b)
{
int res = a + b;
Console.Write(res);
}
static int test1(int a, int b)
{
int res = a + b;
return res;
}
static void Main(string[] args)
{
Console.WriteLine(test1(1, 2));
test(1, 2);
Console.ReadKey();
}

I tried this myself, since I thought you couldn't get anything from void methods and I was confused, but the output for both is 3. Why is void even used if both accomplish the same thing?

brson said it on a greenthreading removal issue on github somewhere, cbf to find it

Do you not know about decidability?

i changed everything to nullptr, still crashes.

could it be because i use memcpy and that increments my ptr somehow?

Hello world in haskell is literally 8 megabytes and the program will be constantly swapping because it generates 1 gigabyte of garbage on every instruction.

Hmm? The void procedures themselves don't return anything. The procedures of other types return values of those types.

Sometimes you want a method to *do* something, but not give you back any data.

I wish people would stop writing C and calling it C++.

That's really going to be a problem that's going to stop you from moving to Haskell, because all you do is write Hello World

>greenthreading removal

That's pre 1.0, i.e over two years ago. I don't believe that's relevant anymore.

>names the least important aspect
this, Sup Forums can fock off
/thread

bar doesn't exist in that scope?

the output is also the same if you just write WriteLine(3) in your main function
sometimes you want to do other stuff with values than just printing

bar is global

would this help

bar,foo = &bar.foo[0];
delete[] bar.foo

Existing C codebase:
>Ah yes, I can work out exactly what is going on here. I don't understand exactly how each function works, but I can see how they fit together.

Existing C++ codebase:
>I've spent 3 hours trying to work out exactly how this clusterfuck fits together, but maybe by the end of the week I'll work out how to change this one thing I need to do.

The ride never ends.

I fail to see how this would not be easily avoidable in the unlikely event you ever had to write something like that

Meanwhile in C you'd have to have a monstrosity of directives to emulate half the functionality of the C++ code

>clusterfuck
That's because most people always go full Java in C++. Stop doing that and suddenly it's an amazing language.

>stop using the features of C++ and just use the C parts
sound advice

How is it not relevant? There is literally no replacement for concurrency except threads or 3rd party memeshit. Trash language.

You don't need to support arbitrary template recursion depth, there's a minimum limit to be conforming so you can cut off a 500 or 1000 (or whatever it is) and fully enumerate all possible combinations and check them.

>what actually happended:
Existing C codebase:
>Ah, yes, I could see what that one letter function would do if it wasn't manipulating data over there in the other compilation unit. Now the only thing I have to do is to fix the zillions of segfaults in that poor, linked pointer based reimplementation of that common data structure.

Should I be using netcat or telnet to test my networking code in current year?

netcat

What does netcat have over telnet?

Using classes and RAII does not immediately imply going full OOP and building AbstractProxyFactoryManagers around everything.

Also, a more realistic sepples version:
>A I understand what this template template of value template does. Now let me just extend this code by introducing a int/std::string union into this modu-

that's not what makes C++ unreadable garbage

functionality and the ability to use it in a script

Well we fixed the boot-up problems.
We are now at 902 out of 1024 bytes. Maybe really gotta move up to attiny85

When is it going to do something useful?

do you C guys actually have jobs?
I've been in the industry for a few months now (just a test jockey for an embedded system), and neither anywhere there nor in school have I ever heard any argument like this. Where do you get this from?

never.
What is usefull?
When is you're fizzbuzz doing something usefull?

That's my problem, I know that they don't return anything, but what does that mean? That it won't print anything to the console unless I tell it to?

Could you give me an example?

Well, from the above example, it's calculating, but I'm mostly confused why there's two types of methods, one that returns something and one that doesn't, or rather, I'm more confused about what return actually does, does it mean that with return, you can assign a value to a new object, but with void you can not?

Sorry for the stupid questions, I'm new.

No, that if another procedure called it, the caller would not get a value back.

>do you C guys actually have jobs?
Embedded systems programmer here (avr/atmega chips) for industrial ventilation regulators. Mostly C but also some asm. We use the iar compiler.

>C++ unreadable garbage
That's what you get for playing oversmartass games with operators. Fucking invisible landmines all over the place.

looks pretty cool dude

what kind of money does an embedded systems programmer make? seems like it'd pay better than a "normal" programmer

why do people feel the need to fuck around with operators so much?

maybe because the language is unreadable?

I wish you weren't a retarded faggot.

What exactly do you mean? Code related is what I tried to do, test1 returns something, test is void, and it's giving me an error that it can't convert from void to int.

int x = test(5, 2);
int y = test1(5, 2);

I'd really like an example as to why void is used, and it would have to be retard friendly.

I wouldn't say that. People see the same operators used in other contexts (vector addition and scalar addition both using + for example) and apply that in programming contexts, I assume.

At work we're using MongoDB, Express.js, MapReduce, and ES6. I just realised: We're literally using the MEME stack.

>Could you give me an example?
Console.WriteLine() would be an example of such a function, you just want it to take a value and print it to the console and don't expect another value back

Working my way through the Haskell wikibook, but I keep getting seduced by s-expressions.

You could assign the returned result to a variable in main, or wherever you called the method like:
int result = test1(1, 2);
Or you could have the program print the result like so:
Console.WriteLine(test1(1, 2))

So basically, when you call the method, it executes and sends the result (or whatever you choose to return) back. Is this making things any clearer? Sorry if I'm shit at explaining this.

Learn them both

you can always use TH
or make your own language


also worst dragon

>do you C guys actually have jobs?
Developing systems for a novel supercomputer architecture. The core code is very tight C. The configuration layer (running off the system) is Python (bleah). It also totally kicks the ass of traditional systems.

Okay so it is
int* x;

or
int *x;

When declaring a new pointer?

Well, you just use void when you don't want a procedure to return a value. Of course, that is ambiguous, but that's because it's context-dependent. For example, if you had fun1() + fun2() to be well defined for integers, you'd expect both functions to return integers, no? Void is used in contexts where you expect nothing back.

It doesn't have anything to do with printing to console. It just means the function/method doesn't concretely give anything back to the caller.

Say I have an array in my program that I'm using a lot. I wanna do some light debugging to check values at certain points, but I'm too lazy to use a dedicated debugger. I may have a function to print its contents easily:

void printArray(int* a, int size) {
for(int i = 0; i < size; ++i)
printf("%d ",*(a+i));

printf("\n\n");
}

Or some shit like that. That way I can call that method whenever i want to print the array, but the function doesnt give anything back to me

the * is attached to each variable, but if there's only one do int* because it's prettier

C made yet another mistake

A function can return an int, or a float, or a string, or MyCustomType... or it could just return nothing (void). In order to be useful, functions either have to return something or have side effects (or both). For instance, a method might return void but change one of it's class's members. Or it might mutate a global variable. In the case of Console.WriteLine, the side effect is displaying text in the output console.

In test() you are causing a side effect by printing text and then returning nothing. In test1() you are not causing any side effects and instead are returning something; you then make use of that something by printing it in Main().

Not that guy, but TH always leaves me bitter. It should be syntactically less noisy.

It's
int * ptr

it's not perfect but at least it exists

either one works. I've been brought up to use the first one, because it just makes more sense ("declaring an int pointer"). It also helps when reading prototypes/specifications:

class linkedList {
...
void remove(node*);
...
};

blah blah

Around 400k sek a year, which comes out to like 45k usd, but my living expenses are only about 750 usd/month (everything included, i.e the rest can go into a savings account), so take that into account.

I will senpai, I will. I'm not sure, but I think I'll read SICP next. Scheme is comfy af.
>th
>thai language
>thorium
Duck Duck Goy doesn't bring up any relevant results.

depends on how good you are. Same as other jobs.

You can make $50k a year you can make $300k a year

They both work and they are both of type pointer-to-int.

I personally prefer int* x, since I find it confusing and annoying to see "int " and thinking "oh, this is an integer type..." and then seeing "*x" and having to quickly correct that to "wait, no it's a pointer type".

However you should be aware of a quirk of C (and, by extension, C++): It binds the pointer symbol to the variable and not to the type. When making multiple declarations in one line, this can trip you up:
int* x, y, z; // Wrong! Only x is of type pointer-to-int. y and z are justs ints!


Your options are to use the other version:
int *x, *y, *z;
or (better IMO) just use multiple declarations:
int* x;
int* y;
int* z;

A raytracer.

Not sure what's causing the artifacts in the reflections though.

slightly better dragon


templatehaskell

does memcpy fuck with pointers somehow? i'm literally out of ideas as to why my program crashes it calls delete[] on a char * that's definitely containing data and was assigned with new