/dpt/ - Daily Programming Thread

Old thread: What are you working on Sup Forums?

Other urls found in this thread:

pastebin.com/af4pDpEg
twitter.com/SFWRedditVideos

averaging 2 ints in c

Rewriting TempleOS in Haskell

Int avg(x, y: Int) {
return x + y / 2;
}
done

rewriting the linux kernel in javascript

>in C
nice reading comprehension

OVERFLOW

>C
That's not C.

Also, by order of operations, it's not even the average.

>x + y / 2
y/2 + x is not the average.

Writing an OS in Lua.

>doesn't know what language it is
>it's not even the average
m8...

>y/2 + x is not the average
ok; I literally didn't say it was

>hue hue i made my own language that does left to right evaluation

>got told and now it's time for damage control
you from Sup Forums lad?

Thanks.
Any other cool projects that require some real world interaction? I'm looking around me but the only thing I can think about automating is vacuum cleaning. But I'm assuming programming a roomba is too far away from a single person's capabilities.

Am I mistaken?

wrong! Int can't overflow; git gud!

You can shitpost all you want, but it's not C.

>lel I'm a gaymur
please leave

I'm continuing my quixotic task of learning Swift so I can write an iOS app for personal use.

I hate everything about this language, Xcode, and OOP in general. I can't even imagine what actual big projects look like when written in this shit.

You monster.

>being this butthurt

>animooooooooooo
REKT
E
K
T

...

What can you already do? Can you create a irc bot that counts how many words have been said in a channel every hour?

>memuuuuuuuuu

...

t. autism

...

Daily reminder that testing if for code monkeys.
Definition U : nat -> Type :=
(fix f (n : nat) {struct n} :=
match n with
| 0 => nat
| S n => nat -> f n
end).

Definition sum : forall n : nat, U n :=
(fix f (accu : nat) (n : nat) {struct n} :=
match n return U n with
| 0 => accu
| S n => fun x => f (accu + x) n
end) 0.

Eval compute in sum 5 1 2 3 4 5.


Check (eq_refl : sum 5 1 2 3 4 5 = 15).
Check (eq_refl : sum 6 1 2 3 4 5 6 = 21).
Check (eq_refl : sum 7 1 2 3 4 5 6 7 = 28).
Dependent types are the future.

>testing if
ok, monkey

What the fuck am I doing wrong here. I'm switching between textures using glActiveTexture and glGet is confirming the textures are being switched but for some reason I can only seem to render the last texture set. This exact code worked fine in OpenGL 3.1 but it doesn't work at all in 3.3+.

I'm using libpng.
pastebin.com/af4pDpEg

...

How is it possible? There is no IO in coq.

Noob
Swift isn't OOP
It has features such as classes and interfaces

It's actually quite nice to write in swift, did a sample Sup Forums app

Better than Java/objective-c

how would i get the first byte from a short (without mask)?
i have tried something like this and it dont work

short s = 12345;
char b0 = *(((char*)&s)[0]);


pls help

>first byte
The lower byte? Or the byte at lower address?

if the short is mapped to bytes 1000 and 1001, i want the one in 1000

I have no fucking idea. I found it trending one night. Code is still there.

Just do
s & (1

#include

#include

typedef unsigned char byte;

int main (void) {
short i;
byte cl;
byte cu;
assert (sizeof (short) == 2 * sizeof (byte));
i = 12345;
cl = ((byte *) &i)[0];
cu = ((byte *) &i)[1];
printf ("0x%4X\r\n", i);
printf ("0x%2X\r\n", cl);
printf ("0x%2X\r\n", cu);
return 0;
}
But beware the bytes order is not portable.

No. But it'd help to have some sort of 'project hierarchy' to see what would I be able to do with certain skill level.

e.g. By the time I'm an old fart I'd like to program a strapped AED so I can fool death if* I live alone. The same with giving the dogs their meals and so on.

char b0 = *(char*)&s;

hey guys how to do this without using cins in C++

Sample
Input 1-5
4
Op
is
not a
faggot

The easiest is of course a mask, but you can always do this

union {
short value;
char bytes[2];
} s;

s.value = 12345;
char b0 = s.bytes[0];


or this

short s = 12345;
char b0 = *((char*) &s);

daily reminder that power to abstract corrupts just as much as the power to use state

short s = 12345;
char b0 = ((char*)&s)[0];
Turnon ur brain pls

>easiest is of course a mask
how? did you think this through?

not portable

It is in fact the MOST portable, assuming you're trying to get the least significant byte.

>how? did you think this through?
Are you stupid or something?

short s = 12345;
char b0 = (0xff00 & s) >> 8;


OH WOW THAT WAS HARD

>assuming
stop assuming
>get the least significant byte
user wants the first byte in memory, you fucking dolt

user didn't ask for that.

Or even if you care about portability.

>stupid
you certainly are

That's why I gave him two alternative options, you fucking imbecile.

What's the point in samefagging?

see

You're wrong. It is the most portable.

>alternative
you don't even know the meaning of that word you shithead

Hi Sup Forumsentlemen I know python really well, I use it for numerical mathematics. But I want to learn a lower level language. I specifically want to be able to create really lightweight games. Do I go for C or C++ ?

C.

What the fuck are you on about?

>I specifically want to be able to create really lightweight games
example?

>wrong
yes, you are

C++

How is it unportable?

you are apparently retarded; let me spell it out for you: when 2 methods give different results, they are not "alternatives"

it doesn't give the required result on all platforms

where are these games going to be played, on a network switch?

anything with enough juice to deal with graphics is going to have enough juice to run Python.

int average(int x, int y)
{
return (x & y) + ((x ^ y) >> 1);
}

It does.

Unity

you continue to be wrong

Are you trolling or what?

>tfw you get in the office on Monday and someone replied with stupidity to one of your posts from Friday in the 404'd thread
>tfw can't refute the objectively wrong thing they said

I actually tested this.

Can someone explain how a bunch of ands, xors and shifts result to an average? I mean, is there a formal mathematical proof?

Tell me which platform it is going to give the wrong result on.

are you retarded or what?

Where is it written in C89 specs that the union use the same memory for each kind of value? Where id documented the memory model of union in C89 specs? I'm not sure that you're code is portable.

Does this work with negative values?

That returns x+(y/2) unless this language can't do order of operations, but that would mean it's behind c.

Just simple 2D games with minimal overhead.
Just as a stupid challenge I guess. I like to optimize for the heck of it. I know it's retarded to do so, but it's fun to see how much you can squeeze out of a program.
Unity isn't lightweight.

Trolling it is then.

>C89

the ones you didn't test on, because you refuse to use logic instead of your retarded trial-and-error

Except, I don't have to use logic because I can read the fucking standard.

>b-but it works on muh computar
fuck off

>says it is unportable
>fails to point out why it is unportable

>b-but it works on all computers that implement C properly
ftfy

>I can read
doubt that; otherwise you'd know C doesn't specify a byte order

how do i access the copy paste buffer from terminal?

i want to do like
cat FILE | copypastebuffernigger

I did, you're just to stupid to understand

C is fine then

Can someone explain what alpha conversion is in basic terms?

It seems really simple, but I may be missing something.

>I don't know C

i have to run 'ntfsfix' on my 2nd hdd every other day or so, is it time to get a new drive or is it just the ntfs fs that is trash?

>i wear my pants on my head

What are you actually trying to do?

>must meme for damage control

signing up for a gym membership

To paste you do:
cat FILE | xclip


If you want to copy into the selection/middle mouse button then:
cat FILE | xclip -selection c


To paste:
xclip -o >> FILE


(The selection argument applies for pasting as well)

>is there a formal mathematical proof?
Ofc