/dpt/ - Daily Programming Thread

trap thread as requested

youtube.com/watch?v=lbMeZUM0slg

previous:

Other urls found in this thread:

ideone.com/yjmrrx
ideone.com/O639wn
ideone.com/uNeuqo
ideone.com/Pwcek7
ideone.com/z55kPJ
pastebin.com/hUpPC8Yi
pastebin.com/uipEv1MD
godbolt.org/g/pL95fP
port70.net/~nsz/c/c11/n1570.html#6.5p7
github.com/7Y3RPXK3ETDCNRDD/dungeon_generator
godbolt.org/g/PBlxw9
godbolt.org/g/7IxRyx
port70.net/~nsz/c/c11/n1570.html#6.5p7)
twitter.com/NSFWRedditVideo

big dick playa here, I'll teach you fags how to C

>linking objectively shitty music

2nd for C#.

tell us how to allocate a variable length 2d array on the heap in C

>spoonfeed us
how about you give your opinion on how to do it and I shit all over it with my superior C knowledge? you know, bait style :^)

She's going to show you an example, you're going to point out how it's objectively wrong, and she's going to spout 'big dick playa' ad infinitum.

>when you found the solution to all software backdoors.

int a[m][n]

int (*a)[m][n] = malloc(sizeof(int[m][n]));

/dpt/-chan, dai suki~

Ask your much beloved programming literate anything (IAMA).

int (*foo)[x][y] = malloc(sizeof(*foo));

or
int *foo = malloc(sizeof(int[x][y]));


Note that there no such thing as heap or stack in the definition of C.

>the second option
>no foo[i][j] syntax

just use
int (*foo)[y] = malloc(sizeof (int[x][y]));

to have the familiar element access syntax of foo[i][j]

Got anything to comment on ?

2 dimensional arrays are a mistake. Don't use them and calculate the index yourself.

>mistake
why?

They're confusing. Don't use multidimensional array.

You're a mistake.

>They're confusing
maybe you just don't know C

if you don't want any abstraction why don't you program in assembly

>They're confusing
fucking Ctards

They are useless.

>arrays are useless
you're an idiot

How impossible is to bypass the HTML code of websites like ManyVids and MyGirlFund and get the videos for free?

Thank you kind frog

Not what I said.

>backpedaling
fuck off already, webshit

>array
Enjoy your botnet.

This thread is cancer.

Why don't you learn C?

Are you illiterate?

>ideone.com/yjmrrx
no workee

>I don't know C nor C++
too bad

>undefined behavior
user...

it's supposed to output 1 2 3 you dingus, fix it if you know C/C++ so well, but you can't because is no workee

>supposed
orly? how about you learn C, you shit?
ideone.com/O639wn
get bent, faggot!

>ideone.com/uNeuqo
still no workee

>it's supposed to output 1 2 3 you dingus
No.
It's supposed to output 1 3 then possibly crash because the last access is undefined.

>still undefined behavior

no shit sherlock, if it was a proper 2d array it would print 1 2 3 with well-defined behavior

>if it was a proper 2d array it would print 1 2 3 with well-defined behavior
No.

m8, you don't know C, stop talking already
here it is with the dumbed down "proper 2d array" for retards such as yourself

KILL YOURSELVES

with a 2x2 (not 4x2) array it's supposed to be 1 2 3


RETARDS

that links back to his original code for me

>with a 2x2 (not 4x2) array it's supposed to be 1 2 3
Not the way you are acessing it.

Is this true?

>I'm a webcuck

ideone.com/Pwcek7
who no workee, fagman?

it's supposed to be contiguous you retards, you fail

>supposed
You're supposed to know what you're talking about, tard.

fuck off with that stupid frog already

is the only sensible option. the other ones are not contiguous.

why no workee tho?

It is contiguous, you just don't understand how pointer arithmetic works.

ideone.com/z55kPJ

you're right, 2d arrays in C are a joke

Say, retard, what do you believe "**(foo + 2)" means? Also, how do you think foo[2][0] could be rewritten?

Followed the programming challenges thing and made an ascii circle generator sort of doodah in Java.
pastebin.com/hUpPC8Yi

Unrelated, I also tried to script kiddie a bit (as in, incompetent, not malicious but I might have pissed someone off whilst testing this) and tried my damnedest to make something that can download porn from e621 by the pageload.
Everything but the download bit works.
Making iframes doesn't download squat.
Window.open() and Window.location() open new tabs or change webpages, not download stuff.
I'm struggling to find something that works.
pastebin.com/uipEv1MD

Last, but not least and the reason I started browsing this thread two weeks ago but I've never asked...
How do I install a C++ library?
I've got SDL and SFML sat on my harddrive and I don't know what to do with them: the installation instructions have been useless for me.
I'm really sorry for being retarded. I know I'm not supposed to ask for this stuff because the answer's always going to be one Google search away.
Still, I'll risk a ban for some guidance.

they're only a mistake because they weren't implemented as a syntactic sugar for calculating the index yourself

>you're right
so you are a retard?
>a joke
you just proved that you're the joke m8

see kill yourself

>malloc is not contiguous
are you mentally ill?

it's an obsolete programming language for the programming techniques of the past.

Yes

Not sure why GCC changed that behavior. The aliasing optimizer has changed since 6.x.

Type safety.
Purpose of 2d arrays is also to have an array of 1d arrays.

nice double indirection fag

you got told & rekt hard tho

at the end of the day you're the one stuck using (a subset of) C because anything else is "too confusing"

>Not sure why GCC changed that behavior.
Because it was wrong. They simply fixed it.

>too confusing
yeah, we all saw how simple array access is too confusing for webshits like you :^)

kys

>you're the one stuck
nah, you got it wrong: you're the idiot who's "stuck"

In what situation could it be wrong?

>DELETE THIS

a 2d array should obviously be laid out as [00,01,02,03],[10,11,12,13] etc so *(arr + 4) should obviously map to arr[1][0] (10), anything else is retarded

It doesn't change anything in that case.

if the compiler know that *(char*)n = (char)*n which it should be the case here since it's only constant folding, then the optimization is legit.

Depends on what 'arr' is, and whether you wanted row or column major order.

someone make a macro for using a 1d array with 2d array-ish syntax without double indirection

Alternatives to Büchi automata.

Your face when godbolt.org/g/pL95fP

Clang > GCC

int f(int *n, float *f) {
*n = 1;
*f = 0.1;
return *(char*) n;
}

f:
movl $1, (%rdi)
movl $1, %eax
movl $0x3dcccccd, (%rsi)
ret

When "n" and "f" point to the same thing, it's clear that the return value should not be 1 (it should be -51). That's what was fixed.

i think i'll just stop posting because this captcha is just too cancerous and time consuming, they really crossed the line this time

What language should I start learning?
I'm taking high level math classes in uni but I have literally not done ANY programming before.

I was looking at C mainly to start out.

My purposes for programming are for fun and maybe to work on hacks for mmos and stuff.

Dereferencing (char*)n is undefined behavior due to strict aliasing. See port70.net/~nsz/c/c11/n1570.html#6.5p7

>When "n" and "f" point to the same thing
How is that ever possible?

/dpt/, is there any reason for me to upgrade llvm and clang? I'm using LLVM 7.3.0 now

wait, char is allowed. dereferencing *n would have been undefined.

>That's what was fixed.
>""""""""fixed"""""""""
you're saying they threw away the strict aliasing rules?

github.com/7Y3RPXK3ETDCNRDD/dungeon_generator

What can i improve? Or is it good as it is?

Thanks for MIT'ing it because I was actually about to implement a dungeon generator but since your seems to be doing pretty sweet job imma steal it.

godbolt.org/g/PBlxw9
based gcc tho

you shouldn't expect *(char*)f when you do *(char*)n

godbolt.org/g/7IxRyx

kys

void *p = malloc(max(sizeof(int), sizeof(float));
f(p, p);

pls halp som1

>what is strict aliasing

Allocated objects have no declared type.

fuck off, if you have int* and float* and you set a value to float* you shouldn't expect to get it from the int* unless you use -fno-strict-aliasing

When they point to an allocated object.
No, they just fixed the bug where they got over zealous with strict aliasing.
You should. Because the aliasing rules allow it.

But that's stack not heap you hapless techno weenie.

just another example of C being shit then

>float* you shouldn't expect to get it from the int*
nobody gets it from int*, it's accessed through a char*, which is allowed by strict aliasing

>sour grapes

its this the correct way to get the number of elements in points?

int points[] = {
{0, 0},
{1, 1},
{2, 2},
{3, 1}
};

int size_of_points = sizeof(points) / sizeof(points[0]);

it's just a loophole, it goes against the spirit of strict aliasing, you're supposed to get the char* from the float* not the int*

They didn't broke strict aliasing. Strict aliasing doesn't apply to the character type (see port70.net/~nsz/c/c11/n1570.html#6.5p7)

You _can't_ dereference *n but you _can_ dereference *(char*)n because you are passing through the character type.

it's like

char foo(float *y, char *z)
{
*z = 45;
*y = 1.0;
return *z; // need a fetch, *z is compatible with *y
}


or

int f(int *n, float *f) {
*n = 1;
*f = 0.1;
char *z = (char *)n;
return *z; // since *z is char, dereferencing z is not undefined behavior even if z = f
}