[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: 22
File: Cruzin' for a bruisin'.webm (395 KB, 854x480) Image search: [Google]
Cruzin' for a bruisin'.webm
395 KB, 854x480
Previous thread at >>51874414

What are you working on, /g/?
>>
first for Java
>>
First for Java
>>
first for filtering averaging two ints meme
>>
Nth for c#
>>
File: Jobs_2003_rev1.jpg (2 MB, 2370x2166) Image search: [Google]
Jobs_2003_rev1.jpg
2 MB, 2370x2166
Ask a programming literate anything.
>>
First for Java
>>
OOP in languages like Java and C# and C++ is poorly implemented. At least in C++ you can get around it.
>>
>old thread is still on page one
>must be time to make a new thread.
I swear you guys are worse than /vg/ with this shit.
>>
Help me understand entropy >>51880088
>>
>>51880441
see >>51880408
>>
>>51880422
Why did you post a pic of someone who isn't programming literate?
>>
>>51880435
OOP is a tool for reducing code duplication and achieves the task well enough in C++, C# and Java.
>>
>>51880446
>trap thread
What does this mean?
>>
File: 18211.png (98 KB, 400x300) Image search: [Google]
18211.png
98 KB, 400x300
>>51880435
>the Ctard is at it again
>>
>>51880465
it's a /dpt/ thread with the OP promoting faggotry such as crossdressing. lately we've been having a very persistent troll that has been forcing himegoto pics and most of the time he's posted the thread before the bump limit which is a big no-no. it might be the same person as the one that's been posting 3D traps, just that he's moved on to himegoto because he can get away with it a lot of the time.
>>
File: 1.png (29 KB, 1209x705) Image search: [Google]
1.png
29 KB, 1209x705
Making a Caesar Cipher, But wondering how to avoid symbols being included within the shifts. Any tips? I feel like I've made some kind of real obvious mistake.
>>
>>51880442
>>51880088
Those 40 minimum bits include storing information about the order of your cards. Because you don't care about order, you're able to store them in lesser amount of bits.
>>
>>51880381
Thank you for not posting an anime image.
>>
>>51880554
Nevermind guys, I figured it out myself!
>>
File: steve-jobs.png (118 KB, 750x233) Image search: [Google]
steve-jobs.png
118 KB, 750x233
>>51880450
>apple
>mac os
>objective-c
>next
>nextos
>dylan
>swift
>>
>>51880637
>implying objective c is good
>>
>>51880575
Thanks I feel super dumb now
The minimum would actually be 52^7 / (7!) right?
Apparently that's only 20 bits which means my thing is terrible
>>
>>51880503
Himegoto anon here, I'm not posting anything but himegoto.
You're thinking of someone else.
>>
>>51880657
log(52^7 / (7!))/log(2) = 27.6038700086
>>
>>51880381
trying to understand the following Python quine
a='a=%s;print a%%`a`';print a%`a`
>>
>>51880685
I'm too braindead to think apparently, I'll just take your word and fail to form an opinion on it.
>>
File: K&R himegoto.jpg (159 KB, 500x700) Image search: [Google]
K&R himegoto.jpg
159 KB, 500x700
>>51880503
What's wrong with himegoto?
>>
>>51880726
It means you were much closer to it than you thought. ~27.6 bits, not 20 bits.
>>
>>51880727
it gets really fucking old to see it every goddamn thread especially when it's forced by posting before the bump limit
>>
>>51880727
himegoto is cute and i would be interested in fapping to it but its not really related to programming and i dont like when people give anime haters an excuse to shit up 4chan even more with their offtopic complaints which never get cleaned up
>>
Literally what's the point of classes? They're useless as fuck
>>
Anyone can confirm this shit works with every number?
/* Averages two ints without overflow */

#include <stdio.h>
#include <stdlib.h>

int avg(int a, int b)
{
if (a % 2 != 0 || b % 2 != 0) { /* if one of the numbers is odd ... */
if (a % 2 != 0 && b % 2 != 0) { /* it checks if both are odd */
if (a < 0 || b < 0) {
return a/2 + b/2 + (a%2); /* magic */
}
return a/2 + b/2 + (a%2 + b%2); /* division truncates */
} else { /* if just one is, then add 0.5 */
return a/2 + b/2 + 0.5;
}
} else { /* if they are both even */
return a/2 + b/2;
}
}

int main(int argc, char *argv[])
{
if (argc == 3) {
int a, b;
a = atoi(argv[1]);
b = atoi(argv[2]);
printf("%d", avg(a, b));
} else {
printf("%d", avg(-1, -1));
}
return 0;
}
>>
>>51880785
To bind code and data together.
>>
>>51880761
so basically it's a non-issue, ok
>>51880771
>fapping to himegoto
what the fuck is wrong with you, you homo

>>51880785
think of structs, except you can embed functions inside of them, real functions, not just pointers to functions
>inb4 what's the point of structs? They're useless as fuck
>>
>>51880793
Checked it, doesn't work.
>>
>>51880793
>return a/2 + b/2 + 0.5;
Bad form, will pollute compiler outputs with warnings about truncation. Do an explicit cast.
>>
>>51880793
That shit can be reduced.
>>
>>51880727
>>
>>51880812
>>51880819
>>51880814
Trying to get it working before thinking on reducing it. Yup, it doesn't work with some stuff. Working a bit more on it.
>>
>>51880785
To create composite types and interface with them.
>>
>>51880839
>>51880793
>atoi
Don't use atoi, it's unsafe, use strtol
>>
>>51880839
int avg(int a, int b){
return ((double)a + b)/2;
}


Here. Don't torture yourself.
>>
>>51880793
kek
>>
>>51880858
Just check to make sure every character in the string is a numeric value, and add an exception for the first char being a '-' char for negative numbers.
>>
>>51880831
Thank you!
>>
>>51880875
>Just check to make sure every character in the string is a numeric value, and add an exception for the first char being a '-' char for negative numbers.
Which strtol does for you.... Seriously, just use it instead.

char* sptr;
int number = strtol(argv[1], &sptr, 0 /* base 0 = decimal, octadecimal and hexadecimal */);
if (sptr == NULL || *sptr != '\0') { fprintf(stderr, "%s is not a number you idiot\n", argv[1]); exit(1); }
>>
>>51880864
That will still round down the result when it's cast back to an int. Better would be:
int avg(int a, int b){
return ((double)a + b)/2 + 0.5;
}
>>
>>51880911
It depends entirely of preference. I think integer average of 4 and 5 should be 4, nd for my problem it might be the best approach.
>>
Python should never be a first language.
I never would have appreciated how easy everything is if I hadn't written everything in C for so long.
Praise the snake.
>>
>>51880930
>>51880911
The problem is, though, that in the real world the average of any two integers is a real number, not an integer.
>>
>>51880953
Thankfully we are not in real world, we are just trying to apply averaging to solve a particular problem.

If you want floating point result, just change return type.
>>
how to average three ints in C
>>
>>51880971
WEBCÃœCK DETECTED
>>
>>51880974
int avg(int a, int b, int c)
{
return (a + b + c)/3
}
>>
>>51880998
Not again for fuck's sake...
>>
>>51880930
>>51880953
>>51880911
>>51880875
>>51880869
>>51880864
>>51880858
>>51880812
Which test cases should I use to know if it works or not?
>>
>>51881000
breaks with ints larger than
715827883
>>
>>51880756
26.9953363841
>>
How long have we been trying to average two ints in C now?
>>
>>51881000
int average = avg(INT_MAX, 2, 3);
>>
File: aaaaa.png (83 KB, 694x801) Image search: [Google]
aaaaa.png
83 KB, 694x801
>>51880793
Here. For your efforts.
>>
>>51881029
It should work with
a = b = math.pow(2, sizeof(int)*8-2)
>>
How to average a varying amount of integers in C?
>>
>>51881037
>long
no, ints.
>>
>>51881029
All of them. Do not come back until you have tested your code on all combinations of two integers.
>>
>>51881037
I've counted five weeks. I guess we could find the real number if we consult the archives.
>>
>>51881066
In the real world one would just use GMP, a library for arbitrary precision arithmetic.
>>
>>51880811
kill yourself
>>
>>51881071
for (int a = INT_MIN; a <= INT_MAX; ++a)
{
for (int b = INT_MIN; b <= INT_MAX; ++b)
{
avg(a, b);
}
}


It works, done
>>
>>51880953
A U T I S M
U
T
I
S
M
>>
>>51881029
>test cases
you don't prove it correct with test cases, you web nut, you prove it correct with reasoning and knowledge of the standard
>>
>>51881087
>In the real world one would just use GMP, a library for arbitrary precision arithmetic.
No, you wouldn't. Because
1) GMP is deprecated, you should use GNU MPFR instead
2) Including a fucking third party library for calculating the average of two ints is Webdev-tier. Go back to your jQuery and angular.js
>>
Can anyone help me? It boggles my mind at what the book really wants from me:

7. Show how a short-circuit AND can be used to prevent a divide-by-zero.

Do I code it?
Or do I just describe an example doing it?

I know that I can show it similarly like the 1 0 bit operation or a logical true false sentence...

Let 1 be T for True and 0 be F for false:

T F T ^ F
--------------
T F F
F T F
F F F
T T T
>>
>>51880974
int average2(int a, int b) {
return (a >> 1) + (b >> 1) + (a & b & 0x1);
}

int average3(int a, int b, int c) {
return average2(average2(a, b), c));
}
>>
>>51881117
>units tests are only for web
you're embarrassing yourself now
>>
>>51881108
>it is autism to point out that the average of 4 and 5 is actually 4.5
How did you people even pass high school?
>>
>>51881117
I think TDD somehow seems to attract the biggest retards in all of programing. There are some who seems to think you can't know any piece of code is correct until you write some kind of shitty unit test for it, which is probably more likely to contain bugs than the code it's testing.
>>
>>51881134
>thinks he can prove C code to be correct with test cases
anon, you might as well return to /wdg/
>>
>>51881127
>calculating the average of two ints

>reading comprehension
The question was about averaging an ARBITRARY NUMBER of ints, which you are unable to do in C, I'm 100% sure.
>>
>>51881136
>/dpt/ - Daily Programming Thread
>ints, not integers, not real numbers, I N T S
kill yourself
>>
>>51881133
that average2 doesn't work.
avg(-6, -7) should return -6
>>
File: programming-goto-guy.jpg (14 KB, 250x250) Image search: [Google]
programming-goto-guy.jpg
14 KB, 250x250
>>51881117
Actually, you prove it correct with mathematical proofs.

Pic related
>>
>>51881136
It's autism to point it out when the problem explicitly states answer should be an integer.
>>
>>51881134
no, unit tests are only for good programmers to use. Not ones who think you need to unit test basic programming logic.
>>
File: iE55839.jpg (107 KB, 700x1243) Image search: [Google]
iE55839.jpg
107 KB, 700x1243
>>51881029
something like this plus some special cases (int_max and int_min)
for (int i = 0; i < INT_MAX; ++i)
{
for (int j = 0; i < INT_MAX; ++i)
{
assert( average(i, j) == ((int64_t)i + j) / 2 );
assert( average(i, -j) == ((int64_t)i + -j) / 2 );
assert( average(-i, -j) == ((int64_t)-i + -j) / 2 );
}
}
>>
>>51881145
No, you can do it with va_list as long as the user also passes how many integers they are passing as an argument.
>>
>>51881153
no, mine rounds down. this is the intended behavior.
>>
>>51881141
this. TDD fags are even more retarded than FP fags
>>
>>51881185
FP is great. Pure FP is however retarded, just like shitty TDD, as most of it seems to be.
>>
>>51881170
>No
No. You were wrong.
Anyway, passing the ints is not the problem. Averaging N ints correctly is the problem and so far I'm inclined to believe that /g/ is unable to do it.
>>
>>51881150
>>51881145
>The question was about averaging an ARBITRARY NUMBER of ints
In that case, use stdarg.

>>51881150
You know that real representations exist too. The average of two ints is not an int.

Are you some kind a retard who defines PI as 3?
>>
>>51881144
No one's trying to prove anything correct.

>>51881164
It's not as simple when you don't have access to larger size long or double floating point units, and having test cases might also help discover bugs in weird compilers.
>>
>>51881184
operations on ints truncate unless specificied otherwise
>>
>>51881160
>look ma', I posted something
fuck off
>>
>>51881132
Code it and explain why the short circuiting prevents it. You can't show it using truth tables, short-circuit logic works by only partially evaluating the truth table.
>>
>>51881198
>In that case, use stdarg.
lol, passing the ints to a function is not the problem. Averaging N ints correctly without overflow and with proper rounding is, and /g/ is unable to solve it.
>>
>>51881150
>doesn't know that both float and double exist as real representations

>>51881162
>It's autism to point it out when the problem explicitly states answer should be an integer.
It doesn't, it simply states:
>How do you calculate the average of two ints [in C]?
The average of two ints is not an int.
>>
>>51881197
Use 8 byte float to calculate sum and then divide by count :^)
>>
>>51881133
The average of three numbers is not the average of the average of a and b, and c.
>>
>>51881198
>The average of two ints is not an int.
so why does this work in a strongly typed language:
int a = 1;
int b = 2;
int average = (a + b) / 2;


KILL YOURSELF
>>
>>51881199
>No one's trying to prove
not you, anyway, since you're a fucking retard
>>
>>51881213
So you're not autistic, just uninformed. Good for you.
>>
>>51881231
Average will be 1, not 1.5
>>
>>51881212
>Averaging N ints correctly without overflow and with proper rounding is, and /g/ is unable to solve it.
It isn't complicated. Why on earth would you include a FUCKING library to do so?

Go back to jQuery
>>
>>51881213
>in C
>average of two ints is not an int
m8...
>>
>>51881234
?
>>
>>51881213
you legit have autism m8

>average two ints in C
there is not enough information to infer that it should be a float or a double.
>>
File: Capture.jpg (75 KB, 887x401) Image search: [Google]
Capture.jpg
75 KB, 887x401
Im trying to make this thing print random images, different colored cars, and im not sure what im doing.

public FroggerComponent(String filename)
{
setPreferredSize(new Dimension(WIDTH*PIXELS,HEIGHT*PIXELS));
readRow(filename);

String[] images = new String[]{"0.png","1.png","2.png","3.png","4.png","5.png"};
JLabel MyImage = new JLabel(new ImageIcon(
images[(int)Math.floor(Math.random()*images.length)]));

frog = readImage("Images/frog.png");
lily = readImage("Images/lily.png");
car = readImage(MyImage);
readRow("Images/world.txt");
reset();
}
>>
>>51881231
>calling the variable average makes it the average

>>51881235
>So you're not autistic, just uninformed. Good for you.
Nice deflection, where does it state that the answer needs to be an int?
>>
>>51881240
which is 100% accurate within the precision of ints.
>>
>>51881257
In original problem, the one we're talking about. It's not in this thread, before you ask.
>>
>>51881257
>where does it state
>I only know js
>everything should be double
came all the way here from /wdg/?
>>
When is this average shit gonna die off?
For the last 3 or 4 days it's been absolute garbage. More so than it usually is.
With the trapfaggotry, anime arguing, language shilling, and general forced-meme faggotry, reading this thread is completely painful.

Can someone just post what they're working on? Or can someone start a group project? I can make the logo :^)
>>
>>51881257
KILL YOURSELF

YOU ARE EVEN MORE AUTISTIC THAN I AM

FUCKING KILL YOURSELF MY MAN
>>
>>51881248
>there is not enough information to infer that it should be a float or a double.
Yes there fucking is

>average
As
In
Fucking
Arithmetic
Mean

How autistic are you to believe that since the input is two ints then the answer MUST be an int?

Rule of thumb: Read the question before answering.

>>51881243
See above
>>
>>51881276
It will end when someone successfully does it
>>
>>51881276
>When
when you get it right or gtfo, webcá Žuck
>>
>>51881290
K I L L Y O U R S E L F
I á Ž I
L á Ž á Ž á Ž L
L á Ž á Ž á Ž á Ž á Ž á Ž L
Y á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž Y
O á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž O
U á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž U
R á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž R
S á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž S
E á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž E
L á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž L
F á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž F
>>
>>51881291
No it won't. Shut the fuck up.

>>51881296
Hey, "big dick playa" faggot. Go off yourself.
>>
>>51881291
We have you dumb fuck.
>>
>>51881271
>In original problem, the one we're talking about.
Post the original problem then...

>>51881275
Go back to /wdg/
>>
How do I regex in C?
emailvalidation.c:43:29: warning: unknown escape sequence: '\w'
status = regcomp(&regex, "\w.*\@\w*\.\w*", 0);
^
emailvalidation.c:43:29: warning: unknown escape sequence: '\@'
emailvalidation.c:43:29: warning: unknown escape sequence: '\w'
emailvalidation.c:43:29: warning: unknown escape sequence: '\.'
emailvalidation.c:43:29: warning: unknown escape sequence: '\w'
>>
>>51881241
>It isn't complicated.
All talk, no substance.
You're unable to do it.
>>
>>51881275
I'm not the one who includes jquery to calculate the average of two ints in C.
>>
>>51881308
escape the backslashes
>>
>>51881302
>big dick
swinging past yo' kneeeeees!
>>
File: 1422808766386.png (302 KB, 1920x1080) Image search: [Google]
1422808766386.png
302 KB, 1920x1080
I like niggers.
>>
>>51881320
Should the average of two ints be the floor or the ceil?
>inb4 a float
>>
>>51881330
Fuck off back to highschool, this is an 18+ site.
>>
>>51881307
In C, calculate an integer average of two integers.
>>
>>51881308
You need to escape those \'s man.
>>
>>51881341
>my ass still hurts from the previous threads
then go back to your html tutorials
>>
>>51881340
It should be correct arithmetic rounding.
floor for [0 ... 0.5[
ceil for [0.5 ... 1[
>>
>>51881346
>>51881329
ok, now my program is telling me that regcomp returned a non-zero value because it didn't like my regex.
>>
File: 1400603790863.png (110 KB, 344x278) Image search: [Google]
1400603790863.png
110 KB, 344x278
>>51881337
>mfw I rolled fuckin 1337

PS: what is a fuckin website generator? how do I have to understand that shit?
>>
>>51881340
truncate, i.e. round toward zero
>>
>>51881340
Should be consistent and explicitly specified which it is. Either is fine.
>>
>>51881340
>Should the average of two ints be the floor or the ceil?
No, it should be a real number.

>hurr durr doubles are wasteful because muh javascript uses doubles
>herp derp use GMP instead

How autistic is that? Avoiding doubles for all cost...
>>
>>51881341
>18+ site
You're wrong. You want to get told again and make a buffoon of yourself?
Please, anon, don't b8 the big dick playa again; you know he'll just destroy your ass.
>>
>>51881359
That's literally your only ammunition. Ever.
>hurr i have a big dick
>hurr go back to webdev im a fuckin tool whos 16 years old
You sure are.
>>
>>51881344
When was this the original?

If you search the archives, you'll see that the original is calculate the average of two ints in C.
>>
>>51881360
you are seriously 100% autistic i swear

there is no one "correct" way to do aithmetic rounding. it could be floor for 3.5 and ceil for 4.5 for instance. always rounding up .5 can cause rounding errors to accumulate. retard.
>>
>>51881384
>it should be a real number
this ain't nodejs, webshit!
>>
>>51881384
fuck off to /wdg/ fucking autistic retard
>>
>>51881391
>got told by 16 yo
REKT
E
K
T
>>
>>51881415
>webshit
Says the guy who wants to include fucking jquery to calculate an average

topkek
>>
>python was written in C
>python can average two ints
is it possible for Guido van Rossum to be smarter than /g/?
>>
>>51881391
Dick Envy: The Post
>>
>>51881442
anyone can include a big int library and do it 1000x slower
>>
>>51881428
>hurr durr pi is 3
>herp derp arithmetic mean is not a real number
>HURR DURR HERP DERP USE A DEPRECATED LIBRARY TO CALCULATE THE AVERAGE BECAUSE I CAN'T DO IT MYSELF
>>
>>51880554
jesus christ talk about horrific colors just use VS's default one ffs
>>
>>51881430
>muh doubles
>muh prototype
>muh memejs
fgt...
>>
>>51881458
>HURR DURR RETURN A DOUBLE BECAUSE I CAN'T DO IT WITH INTS LIKE I WAS INSTRUCTED TO
>>
>>51881455
>big int library and do it 1000x slower
So why include GMP?

REKT
E
K
T
>>
File: 1405453964432.jpg (258 KB, 660x546) Image search: [Google]
1405453964432.jpg
258 KB, 660x546
>/g/ can't average a varying number of ints in C
>tries to deflect from their incompetence by calling each other webshits
>no working code for averaging N ints in C is posted
>>
>>51881458
>herp in js everything is a real number
>derp why is c so hard
>muh css
kill yourself
>>
File: blindeyeswhitedankn.jpg (9 KB, 250x250) Image search: [Google]
blindeyeswhitedankn.jpg
9 KB, 250x250
Prolog error:

Cannot print stack while in 3-th garbage collection
Error: Trapped signal 11 (general protection fault), aborting...

This only happens when I try to find an optimum value via labeling([min(Var)],Var). Otherwise the query runs fine with just label(Var). Anyone know why?
>>
>>51881475
>instructed to
I was instructed to average two ints, not to truncate it. GMP will not return it as int either btw.

REKT
E
K
T

>>51881473
How are doubles webdevtier but somehow including fucking jquery to do it, not? You accomplish the same fucking thing.
>>
>>51881483
c is a dead language.
>>
>>51881488
>muh jquery
>muh html and css solves it for me
go back to /wdg/
>>
>>51881505
>doubles
>webdevtier
confirmed js fag
gtfo to your homescreen thread you useless shit
>>
>>51881363
I'm guessing it means a program or library that will write a static (i.e. just serves file) website when run. Jekyll and Hakyll would be examples
>>
Thread is cancer.
>>
>>51881488
>hurr durr using doubles is webtier
>herp derp using GNU bloatshit to represent arbitrary precision numbers are not
Pythoncluck detected
>>
>>51881510
>what is js
>>
>>51881531
>muh GNU bloatshit jquerytier lib to average two numbers
>>
>>51881554
cá Žuck
u
c
k
>>
I am >>51880793. I am tard, I was doing this all the time when I could just do this. Got it to work:
return (a / 2) + (b / 2) + (a%b%2);
>>
>>51881570
You're just envious of my big C dick
>>
>>51881483
enum {INT_BITS = CHAR_BIT*sizeof(int)};

// depends upon signed integer overflow (undefined behavior)
int avg1(int a, int b)
{
return (((a+b)/2) & ~(1<<(INT_BITS-1))) | (((a/2)+(b/2)) & (1<<(INT_BITS-1)));
}

// avoids signed integer overflow, but has conditional
int avg2(int a, int b)
{
if ((a < 0 && b > 0) || (a > 0 && b < 0))
return (a+b)/2;
else
return a/2 + b/2 + (a%2 + b%2)/2;
}

// avoids signed integer overflow, no conditional either, but most optimizing compilers
// will compile this to a conditional
int avg3(int a, int b)
{
int t = (unsigned)(a^b)>>(INT_BITS-1);
return ((a/2+b/2+(a%2+b%2)/2)*!t) | (t*(((t*a)+b)/2));
}
>>
>>51881546
>I don't know C
>I want muh animu back
>where are muh traps
>how about a watch thread
fuck off
>>
>>51881569
>muh doubles
>what is C
>what is int
>what is efficiency
html all the way, amirite, webshit?
>>
>>51881589
Nice memes

But can you average two ints in C?
>>
File: fc,550x550,white.u1.jpg (19 KB, 550x550) Image search: [Google]
fc,550x550,white.u1.jpg
19 KB, 550x550
>>51881588
>avg3
>only 2 arguments
>>
>>51881589
I do know C.
I don't like anime.
I don't like traps.
I don't have a watch.
Kill yourself, you dumb, childish cunt.
>>
>>51881587
>big C dick
>can't average 2 ints
sure thing, csscá Žuck
>>
>>51881617
I wish I was a janitor, I'd do your post for free.
>>
>>51881609
>efficiency
Dude

You're advocating using a fucking GNU bloat library


When using IEEE floating points suffice...

What do you think is the slowest, GNU crossplatform muh FREEEDUMBS boilerplate to avoid wrapping or doing a single floating point div?
>>
>>51881622
>I got told by the big dick C playa
>got rekt all over /g/ for my stupidity
you dare show your face again, web-boy?
>>
if you're all such leet haxxors then why haven't you "raised" the "points" in your bank account yet?
>>
>>51881647
Please get a trip so I never have to see your childish display if inadequacy.
>>
>>51881624
>sure thing, csscá Žuck
ENVIOUS
N
V
I
O
U
S
>>
>>51881611
nigga, I started this meme! I'm the big dick playa
>>
>>51881652
ITT: /g/tards can't hack banks with C.
>>
File: 1415885401040.jpg (21 KB, 400x396) Image search: [Google]
1415885401040.jpg
21 KB, 400x396
>>51881652
You mean good boy points?
>>
>>51881664
>>51881661
just filter off anything including "average" and "ints" in the same sentence, and then "big dick playa" "csscuck" "webfag"
>>
>>51881661
>inadequacy
you're feeling a little short? did my big dick precipitate yours into shrinking? back to /wdg/!
>>
>>51881032
>assumes that int is not 64 bit
>>
>>51881665
>I started this cancer! I'm the autistic manchild
ftfy
>>
Jesus fuck this thread is shit.
>>
>>51881700
No kidding.
>>
>>51881645
dude, you're advocating using js and html! fuck off to /wdg/; this is a thread for programmers, not "web developers"; apply yourself, fgt
>>
>>51881694
breaks with
pow(2, sizeof(int)-2)
>>
Guys, I wanted to learn C but now I'm scared about all this "averaging two ints" "impossible" challenge. Can I just ignore it or is it easy shit that should I be able to do tier?
>>
>>51881685
>csscuck
>webfag
Then how will you know when people address you?
>>
>>51881712
>dude, you're advocating using js and html!
I'm not, but I'll take your shitty "memeing" as your admission of defeat. Now please smash the computer over your head and light your shirt on fire.
>>
>>51881697
>I'm intimidated by c AND your big dick
everyone knows that
>>
>>51881715
Uhm, sizeof(int) doesn't give you number of bits...
>>
>>51881700
This is what we get for using a free-to-use anonymous imageboard. Don't expect serious discussion.
>>
>>51881739
>I'm a web developer
>operations on ints should result in doubles
in that case...
>>
>>51881700
>muh animooooooo
>muh feminine penis
>muh crossdressing
yeah, it used to be so much better...
>>
>>51881753
>>I'm intimidated by c AND your big dick
Thank you for admitting that.

>>51881773
>>operations on ints should result in doubles
Many operations on ints results in doubles.

2 + .5; // tell me how this isn't implicitly cast by C to a double
>>
>>51881729
impossible for "web developers"
>>
>>51881788
>.5 is an int
cssfag detected
>>
>>51881788
>Many operations on ints results in doubles
>on ints
>ints
>plural
>shows sum of an int and a double
>proud
anon, html might not be so bad for you
>>
>>51881811
>2 isn't an int literal
webfag pls
>>
r8 my function

static int
grub_username_get (char buf[], unsigned buf_size)
{
unsigned cur_len = 0;
int key;

while (1)
{
key = grub_getkey ();
if (key == '\n' || key == '\r')
break;

if (key == '\e')
{
cur_len = 0;
break;
}

if (key == '\b')
{
cur_len--;
grub_printf ("\b");
continue;
}

if (!grub_isprint (key))
continue;

if (cur_len + 2 < buf_size)
{
buf[cur_len++] = key;
grub_printf ("%c", key);
}
}

grub_memset( buf + cur_len, 0, buf_size - cur_len);

grub_xputs ("\n");
grub_refresh ();

return (key != '\e');
}
>>
>>51881822
>.5 is an int literal
you can't seriously be this retarded
>>
>>51880381
Can someone link me to the best possible explanation of MVC vs MVVM vs MVP?
Especially one with some examples.
>>
>>51881825

It's a function.
>>
>>51881820
>shows sum of an int and a double
No, I didn't.

I showed an expression with an int and a double, not the sum.

Are you autistic or something?
>>
>>51881825
0/10 can't even average one int
>>
>>51881788
>I'm intimidated by c AND your big dick
we know
>operations on ints results in doubles
that's why you're stuck on bottom of the barrel "html programming"
>>
>>51881843
>webfag gets told
>average 2 ints memer gets RAPED
R E K T
E
K
T
>>
>>51881843
>I showed an expression with an int and a double, not the sum.
>Are you autistic or something?
Said without a hint of irony
>>
>>51881833
You can't seriously be samefagging this hard.

>implying I said it was
>strawmanning this hard because you don't even have a point
>hue hue hue a function that takes two ints MUST return an int because I have severe autism
>>
>>51881843
>+
>not sum
this ain't js, htmlfag, + is addition in C and evaluates to the sum of the operands
at least know the fucking basics before opening your fuckhole
>>
>>51881858
>Said without a hint of irony
>Said
>on an online image board for taiwanese tapestry
It's like you're not even trying.
>>
>>51881861
>huehue
>1+2 is not an int
wtf are you smoking, pajeet?
>>
>>51881877
>>51881843
get rekt by the real big dick playas that don't care about your shitty meme challenges
>>
>>51881877
You don't know C if you don't even know what an expression is.

Read the standard, webfag.
>>
>>51881895
>I don't know C
this is obvious
>>
>>51881885
>+ operand
>function
What are you smoking?
>>
>>51881895
still mad for getting your ass stretched yesterday? no worry, the big dick playa does it all the time; you'll get used to it (unless you run back to your desktop thread)
>>
>>51881911
>backpedaling
Suck my C dick, or is it too big for you?
>>
>>51881913
>cá Žucked by w3c
m8
>>
>>51881921
>yesterday
What? I wasn't even lurking /g/ yesterday. Schizo much?
>>
>>51881943
>pretending
>animoo
>chink
>traps
ishyggy
>>
"big dick C playa" just got rekt by the standard

noise
>>
>>51881922
>i want a big dick
swinging past yo' kneeeeees!
>>
>>51881966
>where muh animu traps at?
stand down, jamal
>>
>>51881206
Thank you.
>>
Hey, guise, is it hard to average 2 int variables in C? /wdg/ says it's impossible. Is it true, /g/? Can you do anything else beyond memeing fizzbuzz all day long?
Tell me, gee!
>>
Can we turn this thread into /dog petting thread/ yet?
>>
Anyone tried compiling C++ in B&R automation studio? Even an empty program in a new project can't compile.
c:/brautomation/as41/as/gnuinst/v4.1.2/bin/../lib/gcc/i386-elf/4.1.2/../../../../i386-elf/lib\libbur_cpp.a : In function `allocModuleMemory'
bur_cpp.c (.text+0x53d) : Error : undefined reference to `bur_heap_size'
bur_cpp.c (.text+0x545) : Error : undefined reference to `bur_heap_size'
bur_cpp.c (.text+0x562) : Error : undefined reference to `bur_heap_size'
bur_cpp.c (.text+0x5b9) : Error : undefined reference to `bur_heap_size'
c:/brautomation/as41/as/gnuinst/v4.1.2/bin/../lib/gcc/i386-elf/4.1.2/../../../../i386-elf/lib\libbur_cpp.a : Error : bur_cpp.c:(.text+0x5ce): more undefined references to `bur_heap_size' follow

Automation studio 4.1.9, gcc 4.1.2 with default flags
>>
>>51882031
no because cats are objectively better than dogs
>>
>>51882014
a/2+b/2+(a%b%2)
>>
>>51882032
check the library flags you tard
>>
>>51882014
>/wdg/ says it's impossible. Is it true, /g/?
/wdg/ is on /g/.
The meme you used is old.
>gee!
C-. You are going to have to try harder if you want to pass Introduction to Bait and do JKS213: Dank Memes.
>>
>>51882038
Cats are evil hellspawns that will claw your eyes out for the hell of it with no warnings or reason

Dogs are man's best friend

>>51882032
Are you sure it's trying to link it as C++ and not C?
>>
>>51882070
>old
I just invented it last week, anon.
>>
>>51882070
>Introduction to Bait
seems to be doing bretty gud: you fell for it
>>
>>51882110
>last week
That's like forty years ago in internet time
>>
file i/o using asynctask on an android application

just finishing it up here
>>
>>51882126
Then I'll come back tomorrow with a new one. We need to keep this thread fresh!
>>
>>51882143
webcuck

webcucks everywhere
>>
>>51882160
wat

are you calling me a web developer
>>
>>51882170
>can't even average two ints in C
>C is hard
>muh js and js.io and async meme.js
>>
>>51882147
finally. now I can rest in peace knowing I can average two ints.
>>
>>51882197
dude this post is the first time i posted in this thread:

>>51882143

maybe i should just leave
>>
>>51882206
Just don't respond to them. Making everyone leave is their goal.
>>
>>51882206
>leaves in shame because he can't average two ints
I wish more csscucks here followed your example, so we could improve these threads
>>
>>51882216
Do I need to know how to average two ints to be a good C-grammer?
>>
>>51882082
So far I didn't even change anything, it's the default configuration made by b&r. I'm clueless.
But hey, at least I can get C to compile with -std=gnu99
>>
>>51882253
Well, it looks like those linker issues you get when you try to link C++ compiled code as not-C++.
Thread replies: 255
Thread images: 22

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.