[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 20
File: daily programming thread2.webm (2 MB, 600x338) Image search: [Google]
daily programming thread2.webm
2 MB, 600x338
old thread: >>52939611

what are you working on, /g/?
>>
First for Go.
>>
Reminder that Python is not a good language
>>
What's the best text editor and why is it GNU nano?
>>
Common Lisp is not the best language, but it's the best dynamically typed language.
>>
>>52942409
How can I make a data structure with a type parameter in Go?
>>
>>52942393
I'm not working on anything, I just waste my time watching animu.
>>
>>52942431
Reflection
>>
>>52942411
Reminder to check for autism as early as possible.
>>
>>52942441
>half of /g/ in a nutshell
>>
Someone with a Twitter tell based Milo about that triggering BBC headline.
>>
>>52942411
Reminder that the obvious is obvious.
>>
>>52942431
>>52942442
go (de)generate
>>
>>52942442
u avin a giggle m8?
>>
>>52942393
Learning x86 assembly as my first language

>>52942425
What's so great about nano?
>>
>>52942393
kill yourself
>>
>>52942460
Reminder that Python literally cannot do 2 things at once.
>>
File: kill_yourself.jpg (56 KB, 579x567) Image search: [Google]
kill_yourself.jpg
56 KB, 579x567
>>52942483
>>
>>52942495
it's lightweight, easy to use and is just useful enough without going full autismo and spending weeks "learning your editor".
>>
File: emacs@arch_061.png (373 KB, 2556x1039) Image search: [Google]
emacs@arch_061.png
373 KB, 2556x1039
>he doesn't compile to PDF
How does it feel to be a shitgrammer, /dpt/?
>>
>>52942495
>What's so great about nano?
People who are too lazy to learn vim can feel smug because at least they're not using notepad.

>>52942526
You can be as productive in vim after 5 minutes of learning it as you can in any other editor. After 30 minutes, you'll be doing even better.
>>
>>52942495
Serious? That's a poor choice. x86 assembly code is hardly portable.
>>
http://www.bbc.co.uk/news/technology-35559439

How can men even compete?
>>
>>52942541
>third time
>>
>>52942495
>What's so great about nano?
It's more usable than Vim without being as bloated as Emacs.
>>
File: strong woman in the military.webm (2 MB, 613x360) Image search: [Google]
strong woman in the military.webm
2 MB, 613x360
>>52942541
>>
>>52942540
Well what architecture do you recommend then? I have processor that uses x86 and figured i learn that
>>
>>52942539
how the fuck is vim any more useful than nano?
Do you type on one of those topre HHKBs and only use vim because your keyboard has no arrow or navigation keys?
>>
>>52942565
vim is the most usable editor m8

but nice b8
>>
>>52942571
Hope that gun's not loaded. She's pointing it all over the place.
>>
>>52942580
Time spent reaching to the mouse or arrow keys for navigation is time wasted, friend.
>>
>>52942575
I'm saying it's a poor choice for your first language.
>>
Rate my feminist int averaging function
int average(int feminine, int masculine)
{
return feminine; // all numbers are equal
}
>>
>>52942571
kek i like how they aren't helping her up like whiteknight millennials would
>>
>>52942571
obligatory
http://www.dailymail.co.uk/news/article-2512412/Female-RAF-recruits-100-000-compensation--march-like-men.html
>>
>>52942609
I want to know what's going on under the hood before i do a higher level language like C. It's not uncommon even these days to learn assembly as a first language
>>
>>52942541
>women's acceptance rates are 71.8% when they use gender neutral profiles, but drop to 62.5% when their gender is identifiable

Unidentifiable
>This fixes a crash in foo.cc

Identifiable:
>I AM A PROUD INDEPENDENT WOMYN AND YOUR USE OF THE PHRASE "Disable transparency" IS TRANSPHOBIC RAPE CULTURE
>>
>>52942607
>time spent reaching for the mouse
I don't even use arrow keys, I use the nav cluster.
Nano has all the features you could ask for without turning it into a bloated IDE with autocomplete because you're too stupid to learn the libraries you're using.
>>
>>52942571
Patriarchy did this.pdf
>>
>>52942623
kek
>>
>>52942393
What anime is that?
>>
>>52942623
int average(int feminine, int masculine)
{
return feminine; // all numbers are equal expect male especially CIS white male because cis white males are members of the patriarchy as thus the scum of the earth and a such should check their privilege
}

Your code wasn't feminist enough
>>
>>52942628
maybe £100k is too much but i think they do have a case

>According to RAF official policy, female recruits should not be expected to extend the length of their strides beyond 27in. They should also be placed at the front of any mixed squad to dictate the pace. But while undergoing basic training at RAF Halton in Buckinghamshire, the claimants were forced to extend their strides to 30in – the standard stride length for men on parades and marches.
>>
>>52942631
yes it is
>>
>>52942684
>look i ruined the joke
>>
>>52942690
Even if it is uncommon i want to know what the compiler is doing
>>
>>52942691
The joke is women talk too much dum dum
>>
>>52942711
This is a blue board desu senpai
>>
>>52942631
Most computer architecture / operating system classes have introduction to programming (usually a C, C++ or Java class) as a prerequisite.
>>
>>52942429
you're forgetting about Scheme mate
>>
>>52942711
does that pass as legal penor censor in japan? the upperleftmost dick is barely censored at all and the others are just a bit pixelated, not actually hidden
>>
File: Promotion.jpg (17 KB, 320x375) Image search: [Google]
Promotion.jpg
17 KB, 320x375
>>52942711
Thanks to you I'm getting a corner office.
>>
>>52942685
Agreed. It's a retarded requirement that doesn't seem to have anything to do with effective warfare.

It's like not letting people use their dominant eye for aiming.
>>
>>52942713
hate to break it to you but compilers are written mostly in c
or c++ in the case of gaycockcaresser and clang
>>
>>52942751
censorship over there is mostly a formality at this point
the only rule is that you have to censor genitalia if you're selling your artwork for a profit, making it commercial pornography
>>
I'm trying to write a lib for IMDB, but there is literally no documentation.

Any tips for reverse engineering the incredibly vague URL parameters? I can't figure them out for the life of me.
>>
>>52942711
>pretends to not know exactly what anime OP posted by adding "or some shit"
>has gay shit saved on his harddrive

or, how about

>doesn't like that OP posted gay shit
>post gay shit
>>
>>52942734
It's 2016, I have a dynamic IP.

If I get range banned all I have to do is pretend I'm an innocent user caught in it. :^)
>>
>>52942711
PROMOTIONS!

>>52942737
Will learning C first seriously make learning assembly a lot easier?
>>
>>52942784
yes
c is portable assembly that you can actually make useful things in
dont learn c++
>>
>>52942768
Why would you not write a compiler in a language that's easier to formally verify?

baka
>>
>>52942393
Fuck your pedophile anime shit
>>
>>52942797
C++ is portable C that you can actually make useful things in
don't learn C
>>
>>52942812
Most microarchitectures support C and not C++.
>>
>>52942797
anyone who regurgitates the "portable assembler" meme has never used C
The portable assembler meme may have been true in the 80s when all compillers were stupid as hell and every statement represented something 1:1 in ASM.

You know what -O2 does?
It cuts your assembler output by half by doing contrived shit that somehow runs faster than anything you could handwrite yourself.
>>
>>52942799
you'd love python
>>52942812
c is more portable than c++, and i only said that because c is simpler and a better first language
you can go from c to c++, but not really the other way around
>>
>>52942812
>C++
>portable
Practically every platform has a C compiler
Few have a C++ compiler
>>
>>52942821
That's not what microarchiteture means.
>>
>>52942821
que?
>>
>>52942768
>>52942797
Very well, I'll learn some C before tackling assembly
>>
>>52942828
ok, it's more than portable assembler :)
happy?
it's not like you need to use optimizations, i'm sure linux doesn't.
>>
>>52942828
>"portable assembler" meme has never used C
The "portable assembler" meme was created by people who used C for serious things like operating systems, GUIs, and programming languages.
>>
>>52942828
The idea is that you can compile the C code for different architectures. Good luck doing that with x86 assembler
>>
>>52942784
Yes. You learn basics of imperative programming with C. Then assembly language teaches you how it is underneath and you'll have a lot of "ooh" moments when comparing the standard practices and methods for both.
Knowing C will also help you understand what really is happening in the objective-oriented languages (ateast mainstream ones). I think half of their features don't really make sense until you consider the relation of OOP and procedural practices in history of software.
So just study C extensively for now.
>>
File: AHAHAHA.gif (491 KB, 500x220) Image search: [Google]
AHAHAHA.gif
491 KB, 500x220
>>52942861
>>serious things
>GUIs
>operating systems
>programming languages
>>
File: 1431533518890.jpg (129 KB, 710x878) Image search: [Google]
1431533518890.jpg
129 KB, 710x878
>C
>C++
>Portable
The fuck are you guys talking about?
>>
>>52942933

(void) 0
// 100% portable C program
>>
>>52942973
;
>>
>>52942933
If you want to maximize the amount of platforms your program can run on, writing it in C or C++ are the best choice.
>>
>>52942933
C preprocessor makes your programs 100% portable on every platform you intend to support
>>
>>52942973
Wrong.
(void) 0;
/* 100% portable C program */
>>
>>52942393
Not sure if this is the right place for this.

My dad wants me to create a html file that he can host on his server to control his lights and sprinklers.

What can i use to compile, Im looking for something simple.

Just an empty place to put the code, and a display so i can see what happens every time i run it.

Im fully aware that im a fucking chump , this should be so simple but im drawing a blank at finding a simple fucking compiler.

>Put the spoon in my mouth, just this once please.
>>
>>52942995
No it doesn't, the amount of platform specific code explodes exponentially for every platform that isn't GNU/Linux compatible.

Your definition of portable is extremely uncharacteristic of what experienced programmers consider portable.
>>
>>52943040

GO TO WEBDEV FAGGOT

:)
>>
>>52943040
please be bait please be bait please be bait
>>
>>52943040
Neither HTML, Java nor CSS compile.

They're interpreted, typically by web browsers.
>>
>>52943090
Will do

>>52943131
Dont know what you want me to say. i have no idea what im talking about and i want to learn.

How dare i post here and ask for help.
>>
>>52943172
GOOGLE FIRST FAGGET
>>
>>52943171
*Javascript, not Java.
Java compiles.
Javascript typically does not.
>>
>>52943212
Java half compiles
>>
>>52943171
Thanks, I understand now.

I think i can just use one of the free editors and ftp it to the ilon. I have no idea what i am doing but i will figure it out.

Go back to whatever you guys are working on.
>>
>>52943265
>Java half compiles
It isn't compiled to native machine code, but it is still compiled.
>>
>>52943280
Nothing productive whatsoever
>>
>>52943265
And then needs to be interpreted.
And then compiles some more. Sometimes.
>>
>>52942580
regex, /, go to line, ... and the plugins
>>
What do you think makes women write better code? Please don't just dismiss this question as trolling, there's a BBC article about it. The BBC is a respected news source, right?
>>
>>52942625
then she wouldn't be allowed to pass
>>
>>52943040
define expression « lights & sprinklers » for French Moi.

What you want is a web server - server in a different meaning than « this PC is my dad's server » - that is : a program that presents a webpage to clients, the webpage being constituted of html. Using a specially crafted web server, you can create web services with special functionnality, such as responding to commands formulated à la web (example : translate.google.com), and including dynamic data in web pages (example : ipconfig.me).
So yeah, what you want is a web service for controlling lights and sprinkles. Do you know how the computer can access them?
>>
>>52943073
>No it doesn't,
Yes it does.
> the amount of platform specific code explodes exponentially for every platform that isn't GNU/Linux compatible.
Writing some platform specific parts in C or C++ is way easier than say porting the entire jvm to a new platform.
>Your definition of portable is extremely uncharacteristic of what experienced programmers consider portable.
I'm using the practical definition that programmers actually care about.

If you want a program to run on:
embedded devise with cpus varying from 16-32 bit, with one's or two's complement integers, with or without floating point (and possibly non-iee754), with memory capacity ranges from a few KB up to gigabytes, speeds from megahertz to gigahertz, etc.
If that is your span of devices, C is your only realistic choice if you want anything to run at all.

That makes it the most portable language.
>>
is it feasible to start with C as first sprache? and if so what should I go through to learn it, I found learn C the hard way but it says I should know other shit first.

>>52943381
It may be because that because most just aren't interested in doing it at all, the ones that do get into it are serious nerds.

though that's just my assumption
>>
>>52943354
nano has that too

plugins are the admission that your editor is inferior without the use of shitty hacks bolted on to your editor

>>52943381
They get their code accepted more often because most of their pull requests consist of trivial non-code stuff like adding code of conducts and changing all the pronouns in comments to gender neutral ones.

Plus, most men in tech these days are numales who are more than quick to accept a pull request from a woman if it gives them a reason to talk to one.
>>
>>52943354
Macros are also super useful, you can indent multiple lines at once, you can run bash commands from it, etc, etc...
>>
>>52942539
Nano is a very lightweight and simplistic editor that does its job without any bloat or needing any fancy shmancy features
>>
>>52943439
nano has that too
seriously, just read the built-in help
>>
File: 1429234426637.jpg (50 KB, 570x473) Image search: [Google]
1429234426637.jpg
50 KB, 570x473
>>52943411
Go back to /agdg/, you aren't ready for /dpt/ yet.
>>
File: The-C-PROGRAMMING-Language-C.jpg (37 KB, 465x670) Image search: [Google]
The-C-PROGRAMMING-Language-C.jpg
37 KB, 465x670
>>52943417
>is it feasible to start with C as first sprache?
Yes.

>and if so what should I go through to learn it
Pic related.

Don't let other people talk you out of this book. If you do the end of chapter exercises you'll be fine.
>>
>>52943464
You must have replied to the wrong post.
>>
>>52943432
But the BBC article specifically says "Women write better code."
>>
>>52943457
OK, I didn't know that. Honestly, I use Vim because it's a cli editor that I know how to use well.
I don't care much about editors, they should just make coding easier and more pleasant.
>>
this is true, right?

r-right...?
>>
>>52943547
consider suicide
>>
>>52943505
No, seriously go back.

We don't need your "OGL 2.1 and ANSI C for ULTRA PORTABILITY xDDD" shitposting.
>>
https://www.google.co.uk/search?q=Women+write+better+code&tbm=nws

Are you telling me all these news articles are wrong?
>>
>>52943570
how much time do you waste daily, spreading /pol/tard bullshit? do you come from stormfront?

>>52943457
>>52943432
>nano has that too
>CTRL-something for everything
no thanks.

>plugins are the admission that your editor is inferior without the use of shitty hacks bolted on to your editor
uhm, some plugins practically make vim an IDE, m8
>>
>>52943562
i am
>>
>>52942777
I wish I could help you anon, as I had a similar idea for manga-updates.com but am just as lost as you.
>>
File: dolphin.png (305 KB, 674x515) Image search: [Google]
dolphin.png
305 KB, 674x515
>>52942393
WHERE IS THIS FROM I WANT TO KNOW
>>
>>52943511
But you have no way of knowing the difference between "good code" and "shit code" because you're not a programmer.
>>
>>52943565
It appears it is you who needs to go back to adgd then, they really like Unity, C#, Java and JS 'web apps' there.
>>
Hey, gee, how can I average 2 Integers by reference in Java?
>>
Guys, i have a java question. What is the difference between webview and webkit?
>>
>>52943586
They don't have an API yet no? I just did a cursory Google and all I could find was "we're working on it".

IMDB's is fully functioning, but completely worthless. A search for the actor "Nicholas cage" - http://www.imdb.com/xml/find?json=1&nr=1&nm=on&q=Nicholas+Cage

It returns his ID, now if I wanted to get a list of his films I'd have to somehow magically know how to construct a URL that employs an ID as it's parameter.

Who the fuck writes a JSONP API and then provides literally 0 documentation. Worthless sack of shit.

I've never dropped a project this fast before.

It was finally a chance for me to write a library, but there's simply no point in trying to work with it.
>>
>>52943577
>how much time do you waste daily, spreading /pol/tard bullshit? do you come from stormfront?
Probably the worst thing I've ever been called in my life.

Why do you deny all those articles? There's the Guardian, there's the BBC, and loads more respected news sources.

Women are better coders and that's ok.
>>
>>52943547
No. Read about mutability.
For better understanding of Python and programming in general, I recommend reading Data Structures and Algorithms in Python.
>>
>>52943700
wrong, it was indeed True
>>
>>52943699
stop false flagging you shit
nobody is buying it
>>
File: brain problems.jpg (19 KB, 303x296) Image search: [Google]
brain problems.jpg
19 KB, 303x296
>>52943547
>makes a bunch of lists with only one number from x down to 2
>until it gets to x = 1
>then it gets an infinite loops constantly creating and freeing a new list and adding 1 to a list of all 1s
>>
>>52943692
>They don't have an API yet no
No they don't, they've been "working" on one for years now. Hell they still don't even have an android app, and those that tried to make a 3rd party app all gave up.
I'm not sure if it's a good alternative but If you don't plan on messing with user accounts you might consider using the OMDb API instead.
>>
>>52943732
Call it a false flag all you want, the fact remains, science proves women are better programmers.
>>
>>52943388
so they're actually whiteknighting her by giving her a chance to pass.. hehe just joking
>>
>>52943714
Wow, I see it now. I didn't think it through at all.

>>52943837
OK, nobody really cares about gender here.
>>
>>52942833
>Few have a C++ compiler
bwahahahahahaha, found the csscuck
>>
>>52943811
I thought so, but it's so easy to use I didn't feel like writing a wrapper was necessary.

Decided to port some existing code from some 4chan stuff I've been doing into a wrapper for the Vichan API. Seems like a more worthwhile task.
>>
It wasn't peer reviewed and higher acceptance does not automatically equal "better code", how are all those "credible" news sites getting away with it?
>>
>>52943995
Wanna quote someone?
>>
>78.6 percent of pull requests made by women were accepted versus the 74.6 percent accepted by men

I wonder how many of those women were actually trans "women."
>>
>>52943995
>news sites
>knowing what they're talking about
>>
currently having fun with Postgres 9.5
>>
File: Capture.jpg (25 KB, 704x90) Image search: [Google]
Capture.jpg
25 KB, 704x90
>>52944062
>4% difference
>that sample pool difference
>>
>>52943565
>muh webapps
>muh chrome
fuck off to /wdg/ worthless shitstain
>>
>>52942393
Learning Elixir because I wanted to learn Erlang. Will post FizzBuzz when I learn more.
>>
>>52942537

I compile to pei-x86-64. But maybe that's because I'm trying to make programs, not documents.
>>
>All this damage control
Can't you just accept women are better at some things than men?
>>
>>52944096
Holy fucking shit lol
>>
>>52944119
Are you new, or is your bot just shit?
>>
>>52944132
I'm sorry, but I don't understand your question.
>>
>>52944132
His bot is shit
>>
File: cute anime pic 0585.jpg (38 KB, 400x400) Image search: [Google]
cute anime pic 0585.jpg
38 KB, 400x400
>>52944119
>this is what qualifies for trolling these days.
>>
>>52944119
t. Marcosoft Rubio
>>
File: 1267813268776.jpg (34 KB, 294x313) Image search: [Google]
1267813268776.jpg
34 KB, 294x313
>spend an hour figuring how to build Assimp 3.2, can't get it to work
>find out I already have a working Assimp 3.1.1 while browsing through my lib folder
>completely forgot about that
>mfw
>>
>>52943598
>>52942664

himegoto
>>
>>52944224
>Assimp
I thought you were making fun of GIMP at first.
>>
alright /dpt/, which one of you faggots is this? https://github.com/rein
>>
>>52944357
They are productive. Which one do you think?
>>
Is it true that C lacks the flexibility of safely averaging 2 ints? Why are you using such a limited language instead of Rust?
>>
>>52944357
>reimplementing the haskell library in C++
>>
>>52944419
That meme is becoming old.
>>
>>52944357
>lolisp
>>
>>52943381
(You)
>>
>>52944419
you can easily do it by casting to long long ints
>>
>>52944520
NOT
PORTABLE

WHY CANT YOU UNDERSTAND
>>
>>52944469
>still doesn't know the solution
gtfo pajeet
>>
>>52944520
you can also cast to dubs
>>
>>52944585
loss of precision
>>
>>52944565
my bad, they hold AT LEAST certain values, so long long ints might not be able to hold the sum of two ints. but you can use fixed width types like int32_t and casting to int64_t. or is that not portable either?
>>
>>52944419
What? You divide both numbers by two, add them together and if any of them were odd before you add 1.
>>
>>52944605
average of 2 int"s != average of 2 int32_t"s
>>
>>52944615
doesn't give the correct result for all possible inputs

>>52944619
if you want to go the cast route you could use some arbitrary precision library like gmp
>>
>>52944652
Where does it fail?
>>
>>52944652
>needing an external library

I guess he was right, it can't be done
>>
>>52944603
lol no
>>
>>52944689
it can be done in a simple function without any libraries or anything
>>
>>52944697
Don't feed the trolls. Don't even look at them.
>>
>>52944673
it doesn't; he's just a moron
>>
>>52944693
Are you the same faggot from earlier?

You realise an int can be the same size as a long double?
>>
>>52944673
>>52944721
k tard

int avg(int a, int b)
{
return a / 2 + b / 2 + (a % 2 != 0 || b % 2 != 0);
}


>avg(-1, 1)
>1
>>
>>52944565
bwahahahaha, this retard actually believes this!
find me an architecture where (int) (((long long) a + b)/2) doesn't give the correct average
protip: you can't
>>
I see where you guys have been going wrong!
You've been returning integers!

The average of two integers is not an integer
>>
>>52944721
I'm thinking it fails for negative numbers, but that's left as an exercise to the reader. Also I assume 2s complement, but I would kill myself if my computer wasn't 2's complement.
>>
>>52944756
>average of two integers is not an integer
jscuck detected
>>
>>52944741
>>52944757
Yeah, what I was thinking.
>>
>>52944756
an int averaging function obviously returns an int. if you wanted a float you'd simply use a float averaging function and if you wanted a double you'd simply use a double averaging function.
>>
>>52944753
>>not portable
>find me an architecture
You don't belong here, friend
>>
>>52944778
>damage control
MAXIMUM!
>>
>>52944757
>>52944773
>avg(0, 1)
>1
>>
>>52944419
Funnily enough, I looked into Rust ... for about 5 minutes. Dropped it as soon as I discovered that they also punted on doing anything meaningful about integer overflow (because implementing exceptions was too much effort and messed up their nice, clean, oversimplified language).

Providing "safe" arithmetic operations as alternatives which are an unmitigated nuisance to use (and which no-one will actually use) while the infix operators are unsafe isn't a solution. Nor are "optional" checks which are only enabled in "debug" builds.

If the overhead of checking individual operations is too much, then do static analysis so that you can omit the checks when they can't occur. But that would require doing actual work.
>>
>>52944753
/thread
>>
>>52944791
>>52944778
You could just write a valid C compiler that breaks that.
>>52944795
It's rounding up.
>>
>>52944357

I dunno, but I like this guy's choice of language for implementing tests

https://github.com/rein/Monado/blob/master/examples/tests
>>
>>52944807
usually (especially in C) you want truncation for integers unless otherwise specified
>>
>>52944807
>a valid C compiler that breaks that
show it to us or gtfo
>>
>>52944791
Go back to r*ddit you backpedalling 12 year old
Alternatively, show me the paragraph of the C standard that says a double must be bigger than an int
>>
>>52944824
Generally, but it was never defined.
>>
>>52944570
int sgn (int a) {
if (a < 0) {
return -1;
} else if (a == 0) {
return 0;
} else {
return 1;
}
}

int avg (int a, int b) {
int s;
s = sgn (a) * sgn (b);
if (s <= 0) {
return (a + b) / 2;
} else {
int d;
d = (a - b) / 2;
if (d < 0) {
return a - d;
} else {
return b + d;
}
}
}


What did you say?
>>
>>52944775
>obviously returns an int
Obviously doesn't
(3 + 4) / 2 = 3.5

Integers aren't closed under division by 2
>>
File: 5 - Extra-Large.png (4 MB, 8192x8192) Image search: [Google]
5 - Extra-Large.png
4 MB, 8192x8192
>>52942393
I get the feeling that I should have moved on to something more complex than Processing after having tinkered around with dungeon-generation algorithms for several years...
>>
>>52944753
Fails on ILP64 architectures (where int is 64-bit). Not common, but they exist.
>>
>>52944841
back to /wdg/, webcuck!
alternatively, show me a C compiler where adding 2 ints overflows a long long
>>
>>52944865
S P E R G
P
E
R
G

https://en.wikipedia.org/wiki/Rounding#Rounding_to_integer
>>
>>52944741
>a % 2 != 0
Where is it stated in C89 spec that it must be 0 or 1? True can be any non zero value, not just 1.
>>
int avg (int a, int b)
{
return (a/2) + (b/2) + ((a%2) && (b%2));
}
>>
>>52944890
incorrect
see >>52944882
>>
>>52944865
not in C
>>
>>52944882
kill yourself.
>>
>>52944869
have you tested it?
>>
>>52944914
I know that it's hard to recognize that we're wrong but you have to. Otherwise you'll never progress anon.
>>
>>52944880
what does this have anything to do with the C standard?

>>52944882
It's easy to find, at least in c99 and c11. I do not have a copy of c89.
>>
>>52944880
>the C standard is for webcucks
>it's ok to fudge standard compliance
>this code will never be compiled on another compiler

Remember when I said you didn't belong here? That you should go back to r*ddit? (that fucking word blocks you from posting)
>>
>>52944419
Averaging an arbitrary number of ints in C is easy:
static inline int sign(int x)
{
return (x > 0) - (x < 0);
}

int average(int n, ...)
{
va_list args;
int avg = 0;
int odd[2] = {0, 0};
int zeros = 0;

va_start(args, n);

for (int i = 0; i < n; ++i) {
int val = va_arg(args, int);

if (val == 0) {
++zeros;
continue;
}

avg += val / n;

if (val % n != 0)
++odd[val < 0];
}

va_end(args);

avg += odd[0] / 2 - odd[1] / 2;

if (n % 2 != 0)
avg += zeros / 2 * sign(avg);

return avg;
}
>>
Wow /dpt/ is shit today, guess I'll be productive now.
>>
>>52944882
>>52944890
I never intended it to be written that way, I think
(a&1)|(b&1)
is better.
>>
>>52944882
(int) bool is 1 if true, 0 or if false. i thought it was in C89? at least in later standards. and just fucking use a ternary or if statement then you FUCKING FAGGOT

also a correct solution is:

int avg1(final int a, final int b)
{
if(a > 0 == b > 0) {
return a / 2 + b / 2 + (a % 2 + b % 2) / 2;
}
return (a + b) / 2;
}
>>
>>52944936
>It's easy to find, at least in c99 and c11.
Show me.
>>
>>52944943
>Wow /dpt/ is shit today
Don't fool yourself, today is no different than any other day.
>>
>>52944909
int avg (int a, int b)
{ return (a/2) + (b/2) + ((a%2) && (b%2)) ? 1 : 0; }

>>52944945
>|
>>
>>52943669
Is it possible to make an android browser that uses webview without using webkit?
>>
>>52944961
the insufferable sperg meme is relatively new
>>
>>52944965
What's wrong with it?
>>
>>52944937
>my other compiler overflows long long when I add 2 ints
off yourself, css fucboi
>>
>>52944881
I know what rounding is.
>>52944912
"write an equality test"
int x = 4;
if (x = 3) ...
>>
>>52944865
(3 + 4) / 2 == 3
>>
>>52944954
>also a correct solution
nope, still wrong
>>
>>52944965
Far better but still incorrect. Just try it please.
>>
>>52944992
I'm sorry, but you're not only too retarded, but also too incompetent to use this thread.

Why not look for a programming thread on /sci/? You'll probably like them.
>>
>>52944882
> Where is it stated in C89 spec that it must be 0 or 1? True can be any non zero value, not just 1.
Incorrect. Any non-zero value is considered true, but operators which return a boolean can only return 0 or 1. E.g. §3.3.8:
Each of the operators < (less than), > (greater than), <= (less
than or equal to), and >= (greater than or equal to) shall yield 1 if
the specified relation is true and 0 if it is false./38/ The result
has type int.
>>
>>52945016
for which input does it fail you idiot?

>inb4 it fails because of the final
>>
>>52945016
You know, to prove something wrong, a counter example suffices, not hearsay.
>>
>>52944994
>if (x = 3)
end yourself, memejs faggot
>>
>>52944942
shit
int
average (size_t n, int num[n])
{
int avg = 0, odd[2] = {0, 0}, zeros = 0;

for (size_t i = 0; i < n; i++)
{
if (num[i] == 0)
{
++zeros;
continue;
}

avg += num[i] / n;

if (num[i] % n != 0)
++odd[num[i] < 0];
}

avg += odd[0] / 2 - odd[1] / 2;

if (n % 2 != 0)
avg += zeros / 2 * sign (avg);

return avg;
}
>>
trying to do a list combination in F#, the catch is the elements in the list must be sorted into groups of 2,3, and 4
>>
>>52945027
i knew it. sperg got rekt
>>
>>52945026
>got told hard
>out of arguments
>better try some damage control

inb4 pretending
>>
Can you claim inactive github usernames senpai?
>>
>>52944954
>final
wat

>>52944955
6.5.9 Equality operators

>Each of the operators yields 1 if the specified relation is true and 0 if it is false.
>>
>>52945037

.. perhaps you should read the context of my post.
>>
>>52944954
> i thought it was in C89?
It is. I suspect that he chose C89 specifically because the drafts are harder to find (and none of them are hosted by an ISO member body, unlike C99).

>>52944955
For C99, see e.g. §6.5.9
       [#3]  The  == (equal to) and != (not equal to) operators are
analogous to the relational operators except for their lower
precedence.79) Each of the operators yields 1 if the
specified relation is true and 0 if it is false. The result
has type int. For any pair of operands, exactly one of the
relations is true.
>>
>>52944861
Why nobody dare to criticize my solution? Is it correct? Does the C89 MASTER RACE win once again?

>>52945027
Interesting. What is your source? And by the way your solution is still incorrect event if true and false resolve to 1 and 0.
>>
>>52945054
>got told
>general manner of speech

Are you legitimately under 18?
>>
>>52942510
What are threads?
>>
>They're people still arguing that that C is portable despite the fact complex C programs often aren't even portable between C compilers
>Even the fucking Linux Kernel doesn't compile on Clang unmodified
>>
>>52945085
>>final
i had it in a java file for easy testing, and the formatter put in final automatically when i formatted the whole file, and then i forgot to remove it from the function
>>
>>52945111
>what is GIL
>>
Wait, I don't get what was wrong with
return a/2 + b/2 + ((a|b)&1);
>>
>>52945106
>MAXIMUM DAMAGE CONTROL
>hey guise, let's talk about something else
back to jerking it to animu, shitlord
>>
>>52945020

That operator precedence is fucking retarded.

#include <stdio.h>
#include <limits.h>

int avg (int a, int b)
{ return (a/2) + (b/2) + (((a%2) && (b%2)) ? 1 : 0); }

int main(void) {

printf("%i\n", avg(INT_MIN, INT_MAX)); // -1
printf("%i\n", avg(INT_MIN, 0)); // -1073741824
printf("%i\n", avg(0, INT_MAX)); // 1073741823

printf("%i\n", avg(-3, 4)); // 1
printf("%i\n", avg(3, 4)); // 3
printf("%i\n", avg(12, 16)); // 14

return 0;
}
>>
>>52945092
>>52945085
Checked. Bools evaluate to 1 and 0. It is stated in the C89 standard.
>>
>>52945124
C is portable as long as you follow the standard and don't invoke implementation defined or undefined behaviour.
>>
>>52945136

I'm asking a question you fucking 12 year old child. Respect your fucking elders you piece of shit cunt.

Are you under 18?
>>
>>52945135
Negative numbers, but you could probably just test for that too.
Also, that's more concise than what I wrote, nice.
>>
>>52945137
Still incorrect. Try with -3 -3. Your function just tell me that the average of -3 -3 is -1.
>>
>>52945124
you can choose to write it portable or you can choose to use compiler-specific extensions because gcc is the only good compiler anyway.
>>
>>52944880

My google-fu on target triplets is failing me, but I believe that for Tru64 Unix, where sizeof(short) == sizeof(int) == sizeof(long) == sizeof(long long) == 8, it should be

alpha-dec-unix-gcc

Which had support discontinued in gcc 4.6, but should still work for the earlier versions.
>>
>>52945158
>pls let me get away, my ass is already bleeding from that rape I received from your big dick
now back to your designated place, apu!
>>
>>52945124
>the linux kernel needs rewriting in C
new meme material fa.ms
>>
Guys, can someone point me to a quick tutorial on TCP connections using C? I found a nice job opening and it requires a program to be made. That program uses TCP connections, and although i never used TCP with C, I'm pretty good on that language, which means that the TCP thing is the only thing stopping me.
>>
>>52945153
C is only portable as long as use ultra-modern libraries designed specifically for portability.

And pray to god you're don't have a version mismatch.
Thread replies: 255
Thread images: 20

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.