/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

groups.engin.umd.umich.edu/CIS/course.des/cis400/c/hworld.html
en.wikipedia.org/wiki/Bounding_volume_hierarchy
gamedevelopment.tutsplus.com/tutorials/quick-tip-use-quadtrees-to-detect-likely-collisions-in-2d-space--gamedev-374
handmadehero.org/
youtube.com/playlist?list=PLmV5I2fxaiCKfxMBrNsU1kgKJXD3PkyxO
twitter.com/AnonBabble

first for
>recursion is usually unneeded (and sometimes even dangerous)

Ligatures

Keep overflowing the stack, hime!

Explain the output of the following C program (No, the output is not 20).

#include

int main()
{
int a = 1;
switch (a) {
int b = 20;
case 1:
printf("b is %d\n", b);
break;
default:
printf("b is %d\n", b);
break;
}
return 0;
}

>that imperfect program in the OP
Horrible. What kind of asshole would desecrate a mans image like that?

what's with the undergrad meme of doing everything you can to avoid if statements and being obsessed with break?

>"i don't know who this man is and i don't know what this code does but i wanted some retweets on twitter :)"

not sure, but never seen code not in one of the cases before. would b be undefined/garbage?

undefined
maybe 1

Knowing C I'd say that's UB.

but it is 20 :3

Yes, the reason MISRA C does not allow recursion is that it could in fact literally be dangerous. As in "Pushing the brake pedal causes your car to accelerate" dangerous.

was running around trying to find out cause of glitch. was writing a ceasar cipher and learned that if you go out of bounds on in c on a char then it goes ape shit and gives negatives.

example

char c = "z" -> 122 in ascii
c += 10 -> goes over 127

c ended up being -100 or whatever. had to make temp int and cast it and it solved the problem.

I thought the brake pedal on a car was connected directly to the brake hydraulics.
Why else does it feel hard to push when you pump the brakes?

Ask Toyota

Actually..
groups.engin.umd.umich.edu/CIS/course.des/cis400/c/hworld.html

UB

Trying to build my own website but I don't want to do it manually. What is the best open source alternative to Dreamweaver?

...

Well it won't even compile using g++ / gcc.

>trying to do it myself but i dont want to do it myself what's the best program to do it for me

Fucking around with image filters again, and trying to make sense of my implementation of that one guy's 'floodfill but not really' filter.

you are pushing the syntax. Just don't push the syntax.

With -O2 it's 0.
Without it's -13209 (for me)
So assuming gcc isn't broken it's UB.

>Trying to build my own website
this is programming general

Hello /dpt/, i have a question, i have a brilliant idea for a windows app, however i don't know which language i would have to code it with

It involves the webcamera scanning faces of people who turn on the computer. which language would i have to go with? i already know some c++, tried learning it a few months ago but quit because someone stole my laptop

any tutorials on how to write a C compiler in C#?

Changed it from a .cpp to a .c file.. Gcc compiled it's definitely undefined behaviour and should produce a compiler error like the c++ version.

I do not understand why allowing variable declaration within a switch statement would not be a error. Trying to handle scope in a switch statement is idiotic.

...

>I do not understand why allowing variable declaration within a switch statement would not be a error
Not sure. But as I understand switch functions they're just a block where you have jumps to your cases.
So it's not that weird really.
The variable is declared in code though, because declaration isn't a runtime thing. The initialization doesn't happen though.

Weird shit. It's not really that much of an error to my eyes.

Enclosing each case label in braces (i.e. case 1: { ... break; } case 2: { ... usually works fine AFAIK.

Obviously putting a variable declaration outside of a case label entirely is idiot city

Why would you even think that int b = 20 line would be executed? It's outside of any case within the switch statement. The value will be 0 or garbage.

Switch statements are just a fancy wrapper around conditioned goto. You shouldn't be able to goto over the initialization / declaration of a variable.

Yeah that sets a specific scope for the variable and makes sense.

it needs to compile to z80 assembly though

>returns 13 on success
Horrible.

Posted a question on the old thread because I'm a tard.

en.wikipedia.org/wiki/Bounding_volume_hierarchy

Check out the see also section for more

gamedevelopment.tutsplus.com/tutorials/quick-tip-use-quadtrees-to-detect-likely-collisions-in-2d-space--gamedev-374

Sorry, I come from Sup Forums

Thanks!

Ok. well rightly fuck off now.

>Sup Forums

Conservatives can't into IT.

kys

See ya nerds.

>Conservatives can't into IT.
Socially conservative people maybe.

Right wingers and Trump supporters IQ is too low to program or even operate computers.

Will I ever get good enough for high level programming positions if I start programming at 25? Am I too late?

If you didn't start at 8, it's too l8, m8.

No just learn to program right. Unlike 99% of people who learn OOP/meme languages.

But you asking this question isn't a good sign.

IT directly serves the oligarchy that actually runs the world.

Unless you purely work on non paid free open source software and reject the monetary and false governing system you're a contributor.

top kek

Holy, how fucking stupid are you?

Not stupid enough to vote for Trump or believe in the bible.

>Not stupid enough to vote for Trump
what are your actual arguments against trump?

Go ahead. I'll wait.

Will starting from C help me to learn to program right?

Are you kidding me?

unsigned char m8

Apparently stupid enough to not realize one does not get in the running for president without the backing of our true leaders that rule the world the big banks an multinational corporations.

>mfw unit-testing

Yes.
Though this is the best:
Learn the very C basics. Loops, if statements etc. then do this:
handmadehero.org/ Watch that until maybe episode 27.
youtube.com/playlist?list=PLmV5I2fxaiCKfxMBrNsU1kgKJXD3PkyxO
Then this.
Then go on your on own.

If you want can assist you. I already tutor random people for free.
[email protected]

It's like I'm actually on Redditâ„¢.

but who owns and runs the banks?

It's 2016 we don't need another fucking WASP male president.

...

So your argument is:

>its 2016 (current_year)
>we need a woman in the office because i am so tired of seeing men in that position

typical liberal

How about you write a program that calculates the probability of having 44 presidencies in the US and 0 female presidents if it's purely random and there's no bias against women?

presidencies aren't random.

Last names:

Rothschild
Bruce
Cavendish
De Medici
Hanover
Hapsburg
Krupp
Rockefeller
Warburg
Windsor
Soros

I'm pretty sure there is more that can be traced.

>typical liberal
Typical cynic

Company wise most of our banks get their decisions from about 4 groups. Blackrock, State Street, Vanguard, and Fidelity. It is obscene how many financial institutions and corporations can be tied in with these 4.

If you're a employed programmer one of them has something to do with your paycheck.

Programming: The Thread

Technically it is still programming societal programming vs deprogramming.

Our field is naturally evolving towards biological computation.

Yes, by learning to program in C, you'll have a more hands-on experience in type-casting, memory management, array formation/management, string management, memory addressing, convesion/type specifiers, function calls, static typing, compound typing, linking, and more.

Many modern languages do at least one (if not all) of the above for you, so you'll never see what's going on behind the scenes if you were to start with Python, Java, C#, etc., even though all programming languages perform type-casting, memory management, etc.

As to whether you should remain with C for your entire programming career is a different story.

I started programming with Python, but later moved to C. As I learned, Python really holds your hand. This doesn't make Python bad or useless, but learning C will help you become a better programmer AND a far better Python programmer.

Don't forget to crunch your code for maximum performance.

im new to C, is it alright if i have multi-line arrays or is that bad practice?

do whatever the fuck you want. no one cares

Multi-line arrays are quite common and I can't imagine why they would be bad practice.

What's the lowest level API for opening a window on Windows 10?

Multi-dimensional arrays are fine.

I use the window handle to open a window when using windows

thank you all, just making sure i wasn't doing some stylistic sacrilege

Men are just better at a lot of things.

The same as for Windows 3.x.

I fixed a bug in my taggable image viewer Ivy where if you searched for images by providing three or more tags, images that match the first two but not the third would appear as false positives.

...

Basically, I originally did it so that I could cut down on the number of operations the program did, and the

sum -= sqrtN

was to not add square roots twice...
Now that I removed the greentexted part of my program, I'm a lot closer to the answer (4178876 is what I'm getting now, and the answer is 4179871, off by 995, I'm not sure why)

explain

even works irl

1. Select random pixel
2. Floodfill out with that color when neighboring pixel is less than threshold OR when random condition is met (this is what gives it the random walk pattern)

Fairly simple, but it took me about 2 hours to realize that recursion makes GDI+ explode catastrophically.

>neighbouring pixel
So in many ways it seems like a situation where you could be using COMONADS

Is a comonad just the inverse of a monoid in the category of endofunctors?

*dual

it is indeed a comonoid in the category of endofunctors

how do you write a unit test for a class that can have a practically infinite number of states

Python is the language of numales, cucks, and bootcampers.

Don't be that guy.

>co
Just flip the arrows brah

Did you mean Ruby and JavaScript?

Don't write a class that can have an infinite number of states

not always that simple

monoid a where
plus :: a -> a -> a
zero :: a

comonoid a where
coplus :: a -> (a,a)
cozero :: a -> ()

because:

monoid a where
plus :: (a,a) -> a
zero :: () -> a

Those too, but for some reason Python still has a large number of fanboys, whereas people are realizing that Ruby and JS are shit, even the cucks.

Also ridiculing JS fans is like whaling on a retarded kid.

in this sense comonoids can embody resource semantics, e.g.

a -> (a,a)
duplication

a -> ()
destruction