old thread: >>54630928
What are you working on, /g/?
>>54638110
Who is this fluid druid?
>>54638110
who is this testicle molester?
Who is this cock dock?
>>54638110
researching streaming using basic web languages (PhP, JS)
>>54638110
Is that a good book to learn how to use C in if i really know the syntax, have experience in c++, c# and coding in overall?
>>54638209
that's not the original ya dip, the original has no hand
>>54638131
>>54638169
>>54638180
just some camwhore
>>54638110
learning python
Is this cum dump a photoshopped dude or what ?
>>54638209
>Amateur game development general
That's an 8 board I haven't checked in a while. Thanks for reminding me.
>>54638225
>he prefers girls without a hand
jesus, autism levels are through the roof
New to programming here, how can I reverse a string without string.h?
nothing
>>54638243
It's a general in /vg/, you mong.
>>54638258
Pajeet learn to solution first.
>>54638258
That's a hard problem.
>>54638258
select a pivot and xor swap
How the fuck do I create a console application in C using this piece of shit Eclipse?.
>inb4 pajeet-tier retardery faggots.
In the year 2016, does it ever make sense to use float instead of double in C?
>>54638333
Yes, RAM is slow and float is smaller
>>54638363
Can't a 64-bit CPU deal with it natively?.
>>54638348
>joy
>>54638363
Okay, with the exception of saving RAM (which is basically never an issue these days)?
>>54638385
>which is basically never an issue these days
RAM is slow, no matter how much you have.
What is a good book for a total beginner to programming to learn C#?
>>54638333
In the year 2016, does it ever make sense to use int instead of long long in C?
>>54638258
Pajeet pls
>>54638258
store string in LIFO
create second LIFO
stack second LIFO with top of 1st LIFO
unstack first LIFO
repeat
add the ending character
done
So I have a vector of chars, like so:std::vector<char> data{};
It contains a few kB of data in total, now I have a few isntances of std::string and I'd like to search for these sequences in data, what function do I use?
For instance:std::vector<char> data{'a', 'b', 'c', 'd', 'e'};
std::string s{"bc"};
something_find(data, s); // returns iterator to second element or something
>>54638333
Are you fucking retarded?
>>54638452
#include <stack.h>
:^)
>>54638404
Go learn the C syntax and then learn how to program simple programs in C++ after that you are ready to learn C++ classes and such, then move to OOP Java and Java in general, after you are done with that look up for C# videos on youtube, by that time you will master C# in no time (at most one week)
Thats the right approach.
>>54638258reverseString :: String -> String
reverseString = reverse
>>54638399
>>54638408
>>54638433
Jesus fuck, just try it:tic ();
size_t N = 1000000000;
double p;
for ( size_t n = 0; n < N; ++n )
p = sin ( ( double ) n / ( double ) N );
toc ();
andtic ();
size_t N = 1000000000;
float p;
for ( size_t n = 0; n < N; ++n )
p = sin ( ( float ) n / ( float ) N );
toc ();
At least on my machine the first one is faster than the second one. And not just a little bit, it's 12 seconds vs 18 seconds.
>>54638416
Half-assed, but that's the first thing that came to my mind:auto chars = std::vector<char>{'a', 'b', 'c', 'd'};
auto str = std::string(chars.begin(), chars.end());
auto found = str.find("bc");
std::cout << chars[found] << std::endl;
>>54638110
>mfw a physical copy of that book costs 67$ in my country
>mfw i have no face
>>54638624
if you are going to learn to program, you either gonna git gud or gonna fail, if you fail, you fail you suck etc. if you git gud $ 67 is your hour wage and you should care, so my conclusion is that you are retarded.
been screwing around with images still
<--- the latest thing i have made a mess
>>54638594
Nevermind, this one-liner does a better job:auto chars = std::vector<char>{'a', 'b', 'c', 'd'};
auto str = std::string("bc");
auto it = std::search(chars.begin(), chars.end(), str.begin(), str.end());
>>54638677
What exactly are you trying to do?
>>54638677
original one
>>54638696
i tried doing RGB to HSV conversion - but i just put the values back as RGB
so H->R
S->G
V->B
im not sure the HSV stuff is correct though...
>>54638665
Who's talking about learning how to program? I was just pointing the price of that book
Besides i already have it in pdf but it's comfier to have a physical copy
Hey, uhm, sorry for interrupting, but I need to ask. I have read in your wiki that " the C programming language, second edition" is the best for learning C. However, I don't have any concepts nor experience in programming. So, is this book still good even for me as a beginner? I'm studing Mech Engineering, so you may have an idea. Thanks.
>>54638737
It's outdated. "C Programming: A Modern Approach" is a better choice, and great for a beginner as well.
>>54638737
C prog. By Kochan, helped me alot when i first started
>>54638737
K&R doesn't teach programming, it teaches the C language to people assumed to already have some programming experience
not saying you can't learn from it, but it is not the best book if you've absolutely never programmed before
Has anyone here tried using
https://facebook.github.io/reason/
yet?
>>54638763
>>54638766
>>54638775
Thank you guys. I'll check those.
>>54638812
definitely check out the book that other anon mentioned, A Modern Approach, also 'Pointers on C' is a really good textbook
Dubs decide something trivial for me to program
>>54638330
pro-tip: it's never worth trying to use a non native IDE to use a different language unless you are super duper power user. Use Eclipse for Java.
>>54638523
Double is about 1 second slower for me compiling with MSVC (2015/14.0). The difference in size will matter if you're ever doing anything similar to this with SIMD intrinsics, since you'll be performing that instruction on twice as many floats at once.
>>54638926
Given a number x, print the biggest prime number that is less than x.
>>54638926
discrete fourier transform
>>54638926
rolling for data visualization of average cock length by race.
>>54638926
Interpreter for a dynamically typed lazily evaluated purely functional programming language.
Just been making little experiments with the Phaser game library:
http://demos.neocities.org/matrix.html
>>54638928
Eclipse is fine languages other than Java
>>54638926
a basic web server without gui...
...in assembly
>>54638926
TRIANGLE FILL
>>54638926
A simple function plotter
>Want to learn vulkan
>AMD drivers don't support my laptop's gpu
Well fuckballs.
Software implementation when?
[c#] why the fuck is this true?inventory[i][j] = new Item(other.name, false, 1, false);
if (inventory[i][j]. == null)
Debug.Log("it's null");
It shouldn't ever write "it's null" but somehow it does,
why is this null?
>>54638258#include <stdio.h>
int _strlen(char *str)
{
int res = 0;
char *temp = str;
while(*temp)
{
res++;
temp++;
}
return res;
}
void reverse(char *str)
{
printf("Normal: %s\n", str);
char temp;
int len = _strlen(str);
int halfLen = len/2;
for(int x = 0,y = len-1;x<halfLen;x++,y--)
{
temp = str[x];
str[x] = str[y];
str[y] = temp;
}
printf("Reversed: %s\n",str);
}
int main(void)
{
char inputString[] = "oh shit waddup";
reverse(inputString);
return 0;
}
>>54639759
What's that extra dot for?
>>54639759
I that a dot in the second line after [j]?
>>54639805
accident, imagine it's not there
a program to help people queuedodge cheaters in the world of warcraft.
>>54638665
not the best investment to blow $67 on a stupid book if you're a poorfag
>>54638926
liberal news site rss feed in python that also aggregates certain buzzwords from headlines and stores the stats
>>54639824
precursor to buzzword bingo?
>>54639819
Pastebin, please. Enough so that the error actually happens.
Implementing a programming language. It's pretty complicated so I don't think I'll be self-hosted until Christmas.
Ideas for a summer project? 1st year CS student looking to start some projects to pad my resume.
>>54639898
fart mobile app
>>54639889
what backend?
>ace first two interviews
>completely bomb the third
>to my surprise I get told that I did well and they want another interview on wednesday, they just need to check the interviewer's schedule first
>that was an hour and a half ago, I still have no time
>>54639862
http://pastebin.com/eZ32720A
here you go.
btw inventoryCtrl.updateInventory(); checks inventory[][] and there that position is not null
>>54639918
Is there anything but LLVM?
>>54639920
>she
>>54639938
call them back on monday
I am trying to add my java mongo driver to the java class path from Eclipse. How do you do that?
>literally nothing is being done to contain /pol/ anymore.
>literally every other post is pajeet this or poo-in-the-loo that
well, this board is done for.
Novice trying to understand the rounding methods in Java. rint() and round() are easy enough but from what I understand, ceil() will round up to the nearest integer no matter what, so 1.2 will round up to 2.0. floor() is just the opposite, with something like 1.6 rounding down to 1.0.
However, the book I'm using shows the following:Math.ceil(2.1) returns 4.0
Math.ceil(2.0) returns 2.0
Math.ceil(-2.0) returns -2.0
Math.ceil(-2.1) returns -2.0
Math.floor(2.1) returns 2.0
Math.floor(2.0) returns 2.0
Math.floor(-2.0) returns –2.0
Math.floor(-2.1) returns -4.0
The negatives I kind of understand, but why does ceil(2.1) return 4.0 if ceil(2.0) returns 2.0? Shouldn't the former return 3.0? Shouldn't they look more like http://www.javacodex.com/Math-Examples/Floor-and-Ceiling-Example ?
Currently reading how to get a ray from OpenGL.
>>54639553
>neocities
Neat. I didn't know about this.
>>54638523
Try this test:#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
double dubs[1000];
float floats[1000];
int main() {
struct timespec time;
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
for(int i = 0; i < 1000; i++)
dubs[i] = 1.0 / i;
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
for(int i = 0; i < 1000; i++)
floats[i] = 1.0 / i;
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
return 0;
}
Floats are 3 times faster on my machine.
>>54639989
Probably errors in the book
Why java is the best programming language?
>>54640050
It's not.
>>54640049
>Google book
>Homepage, Errata
>Page 122, line 2, Math.ceil(2.1) should return 3.0. Line 9, Math.floor(-2.1) should return -3.0. Line 7 in Section 4.2.4, Math.max(2.5, 3) should return 3.0.
Guess so, thought I was losing it. This book's really been letting me down in odd places the more I work through it.
>>54639989
I think that book might be doing binary floor and ceiling for doubles -> doubles. 2.0 is exactly representable in binary as are all powers of 2 times any magnitude.
>>54639940
Where is inventory defined? Is another thread fucking with it?
>>54640050
It's an absolutely shit programming language. It's got nice tooling, infrastructure, libs, well-tuned and fast-performing virtual machine and all that though.
>>54638258def reverse_string(string): return string[::-1]
:^)
>>54640114
found the solution.
Class Item was inheriting from MonoBehaviour, I forgot to remove that
>>54640050
it's the best for large enterprise applications with many developers working on projects simultaneously because it has great support for OOP and is simple and easy to use so that all programmers can adhere to a consistent style with great ease. it's very safe while still being one of the highest performance languages.
>>54638812
I learned programming on edX with the CS50 course from HarvardX. The teaching language is C (at least for the most part) and it's way more motivating than a book, with videos, shorts, and weekly assignments, which are all really well done.
You should really check it out.
>>54638258
.data
str .word "git gud faggot"
.text
Lea Si, str //message itself
Mov Cx, 14 //length
Mov Bx, Cx
loop:
Mov AL,[Bx+Si]
Mov AH,0Eh
Int 10h
Dec Bx
Loop loop
Mov Ah, 0
Int 16h
Ret
import this to your code by doing __asm{code}. Change .data section into a variable ofc lel. You can thank me later
>>54640201
.data should be "str .ascii "git gud faggot" sorry my bad
>>54638523
The first one is faster because sin() takes a double, so the float version has to do a float -> double conversion before passing the argument in.
Use sinf() for a fair comparison.
Although calculating a single sine is not a particularly useful case.
Where you get speed ups from floats is when you're dealing with arrays of them - they will use half the memory (i.e double the cache utilization) and double the amount of simd work.
And doubles are essenrially useless, the cases where double orecision would be needed over floats are exceedingly rare, if you find yourself needing more precision than float you're most likely gonna want either fixed-point integers or arbtrary precision floats/fixed-point.
why exactly does linus not want people to typedef structs?
>>54640033
>Floats are 3 times faster on my machine.
It's not floats (at least on my machine). If you swap dubs[i] and floats[i] assignments the doubles will be faster. Caching gets into the game probably. Or branch prediction training or some other shit. But it's just the second loop that's faster.
>PLEASE don't typedef structs in C, it needlessly pollutes the global namespace which is typically very polluted already in large C programs.
lol and Ctards don't want namespaces
>>54640033
>#define _GNU_SOURCE
>>54640232
because people are stupid
Why doesn't C have separate namespaces?
I'm pretty sure there's only 4, and that really sucks.
You got the structs, enums, which are all global, the global variables and the local block variable names.
>>54639938
>an hour and a half
calm the fuck down my toad friend. the recruiter is probably busy painting her nails and online shopping.
>>54638523
mobile devices don't even have cpu instructions for doubles
>>54640232
Why don't you just read his fucking email?
One of the reasons afair was that he wants it to be explicit that an argument is a struct and not a *_t typedef over some scalar type or w/e.
>>54640232
Autism, there is literally nothing wrong with typedef struct
>>54640255
>using namespaces in C++ anyway
nice meme
>>54640232
He wants to reserve typedefs for small opaque/handle types, so when he sees a typedefed non-standard type he knows it's only 4-8 bytes.
structs can be be large, and you need to be aware of how much stack space you use in kernel code.
>>54640307DKMM_dank_meme_kTard
>>54640288
>doesn't C have separate namespaces
>there's only 4
/g/
is a lisp machine better at executing lisp than say a >1990 cpu?
>>54640265
Compile it without _GNU_SOURCE or _X_OPEN_SOURCE = some arbitrarily high enough number and see what happens boy.
>>54640303
>literally
kids should leave /g/
>>54640326
lol ktard cmen cshart
>>54640288
Please say you're baiting.
>>54640201
Good god that's garbage.
>>54640354
Give me something wrong then
>>54640326
>not emulating namespaces in C with structs
stay pleb
>>54640364
How?
>>54640390
It's not Python
>>54640288
Namespaces would fuck up the nice property of 1:1 mapping of binary symbol names which is what makes C so popular for system level libraries other languages can easily bind to.
>>54640382
you still need a name prefix for the struct name and the functions
>>54640406
>he can't into 8086
J U S T
>>54640382
>>54640421
Just use a preprocessor hack
>>54640288
Namespaces are useless.
>>54640390
>8086-era shit on a fucking modern machine
>CAPITALIZING THE FIRST FUCKING CHARACTER OF EACH OPERATOR AND OPERAND
Really, you're the MOST autistic.
>>54640457
your mother
unsigned int foo = i != 0U ? bar[i - 1U] : 0U;
is this safe? bar[~0U] will not get dereferenced if i is 0U?
>>54638926
AES algorithm
>>54640618
it's safe
>>54638926
Invert a binary tree
>>54640618
Yeah. Is that default to 0 required behavior or a hack? You could do the subtraction and then check the unsigned offset for OoB.size_t index = i - 1;
assert(index < len);
unsigned int foo = bar[i];
>>54640457
Abstractions are useless, why don't we all just develop in ASM?
>>54640731
>and then check
>assert
you don't know C, do you?
>>54640549
Don't talk to my 8086 or my son 65c816 again
>>54640759
>wife's son
ftfy
>>54640752
What's wrong with assertions?
>>54638926
Come on fags gimme something
I've been making an image viewer where you can set and search for tags. Possibly not the most amazing program out there, but I enjoy it.
>>54640837
do a fizzbuz without modulo operation
hey /g/ i have a question:
in C++, how do i zero out a vector ?
i have thisstd::vector <int> *my_array;
i tried this but it doesnt workmemset(array, 0, array_size * sizeof(int));
>>54640890
http://www.cplusplus.com/reference/algorithm/fill/
>>54640253
You're right. Revised the test a little bit. With this test floats are twice the speed when compiled with -Ofast as one would expect. The order of the tests also don't seem to affect things.#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
#define K 262144
double dubs[K];
float floats[K];
int main() {
struct timespec time;
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
for(int i = 0; i < K; i+=16) {
floats[i] = 1.0f / i;
floats[(i+1)] = 1.0f / (i+1);
floats[(i+2)] = 1.0f / (i+2);
floats[(i+3)] = 1.0f / (i+3);
floats[(i+4)] = 1.0f / (i+4);
floats[(i+5)] = 1.0f / (i+5);
floats[(i+6)] = 1.0f / (i+6);
floats[(i+7)] = 1.0f / (i+7);
floats[(i+8)] = 1.0f / (i+8);
floats[(i+9)] = 1.0f / (i+9);
floats[(i+10)] = 1.0f / (i+10);
floats[(i+11)] = 1.0f / (i+11);
floats[(i+12)] = 1.0f / (i+12);
floats[(i+13)] = 1.0f / (i+13);
floats[(i+14)] = 1.0f / (i+14);
floats[(i+15)] = 1.0f / (i+15);
}
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
for(int i = 0; i < K; i+=8) {
dubs[i] = 1.0 / i;
dubs[(i+1)] = 1.0 / (i+1);
dubs[(i+2)] = 1.0 / (i+2);
dubs[(i+3)] = 1.0 / (i+3);
dubs[(i+4)] = 1.0 / (i+4);
dubs[(i+5)] = 1.0 / (i+5);
dubs[(i+6)] = 1.0 / (i+6);
dubs[(i+7)] = 1.0 / (i+7);
}
clock_gettime(CLOCK_MONOTONIC,&time);
printf("%i.%li\n",time.tv_sec,time.tv_nsec);
return 0;
}
>>54640890
>zero out
Do you mean set the vector back to 0 length or set all members to 0?
>>54640860
I made something similar to that. It was a tree view of tags where you could combine AND and OR in a filter. I used it to sort porn. Yeah, I have deleted it and my porn folder since though.
>>54640910
>twice as fast
>floats are twice as unrolled
wtf.
>>54640928
>memset
>Do you mean set the vector back to 0 length
>>54640928
i mean set all members to 0.
i tried std::fill but no chanceerror: request for member ‘begin’ in ‘((Graph*)this)->Graph::my_array’, which is of non-class type ‘std::vector<int>*’
>>54640910
Is that code supposed to be a joke or something?
>>54640939
That's why it's twice as fast. L1 cache is 64 bytes. I unrolled that shit to utilize the entire L1 cache. i is just a value in registers so we got room for 16 floats.
>>54640950
>non-class type ‘std::vector<int>*
Either replace .begin with ->begin or dereference whatever shit you're calling begin on like this (*shit).begin()
>>54640953
No it's called loop unrolling. It's an optimization technique.
>>54640890fill(begin(*my_array), end(*my_array), 0);
>>54638219
Yes. It is essentially a reference. If you have experience in c++ and c# then you pretty much know C.
>>54640995
Don't compilers do that anyway? I mean, if there is a program constant that surely it shouldn't be difficult for a compiler to generate code to that effect.
>>54638926
open source alternative to techsmith screen capture codec, when you have time left over also build a streaming app and platform for 60fps 1080p/4k with it
>>54641014
thanks!
>>54640949
Seems like he is new, asking a question like that. He probably doesn't know what he wants.
>>54640950
How about a fucking loop? Simple enough.
>>54640974
>L1 cache is 64bytes
What.... You mean a cache line? Also that's a retarded assumption. You do know unrolling increases performance? How about limiting the float loop to 8 just like the doubles. Also using -Ofast might vectorize your code, of course you'll be processing floats twice as fast. After you fix those issues retest. Or is that the point? XMMs and YMMs can hold two times the floats?
>>54640890
Why the fuck would anyone want a pointer to a vector?
Do you understand the concept of managed resources?
Writing a ray tracer in c++. Finding the normals on a cube is giving me a headache. I managed to implement recursive raytracing with refraction and reflections but I can't find which fucking side a point on a cube is on.
>>54641054
That is the point. Floats are better because they're smaller.
And L1 cache is definitely 64 bytes on most home computers.
>>54640860
>tfw I was planning on doing something similar but never got around to it
Do you mind sharing the source code? I'd like to see what method you used to store the tags.
>>54641078
>64 bytes
kilobytes dude.
>>54641077
Also add that I'm writing this all on a chromebook. Because fuck windows I don't have more than $200.
>>54641091
This is the 90s pal
>>54641108
I'm not your pal brah
>>54641078
No... L1 cache lines are 64 bytes on x86_64 computers. The L1 cache is usually a few KB.
>>54638333
Greater precision means greater error. Use only as much precision as you need.
>>54641116
pal is a colour format dumbass
>>54640910
This one actually has a difference between -mno-sse and -msse2. The speed difference seems pretty consistent with:
https://software.intel.com/sites/landingpage/IntrinsicsGuide/#techs=SSE,SSE2&text=_mm_div
>>54641089
https://github.com/lehitoskin/ivy.git
It's written in Racket and it uses Racquel to access a sqlite database. Essentially I have a table for images and their associated tags so that I can grab the tags and display them in that text field you see in the screenshot. Then there's a second table for the tags themselves and a list of images that are associated with them, for easy tag searching.
If you'd like to see some specifics, I'd suggest looking at the db.rkt file.
>>54641199
Also he is testing this with division. Which is one of the only operations where there is a difference in execution time between single and double precision on the x87.
>>54638258reverse :: [a] -> [a]
reverse [] = []
reverse (x:xs) = reverse xs ++ [x]
You're using Haskell, right? I mean it's 2016, who isn't...
>>54641199
What differences are you seeing? I'm seeing the exact same output. I'm also using a 5 year old amd cpu though.
>>54641280
that's a shitty reverse, even by haskell standards
>>54641281
-mno-sse gives:
>1528553, floats
>1636849, doubles
-msse2 gives:
>673979, floats
>1336475, doubles
I'm using a Haswell CPU.
>>54641281
One is using XMM registers and the other is using the x87 stack. XMM registers are an order of magnitude faster. You've obviously fucked something up.
>>54641280
reverse' fold1 (flip (:)) []
>>54641349
Neat. I guess -mno-sse makes the performance computation bound rather than memory bound.
>>54641280
fucked that up
reverse' = foldl (flip (:)) []
Is it possible to write this in one line in python 3:import os
from os import path
>>54638256
>girls
I have a C++ question.
I have a function something liketemplate <typename T>
int foo(T *__restrict x, T*__restrict y){...}
I give it a C wrapper:int foo_int(int *__restrict x, int *__restrict y){
return foo<int>(x, y);
}
Naturally I pass two int*'s into foo_int. But for some insane reason, T gets interpreted as double. Even more confusingly, if I addprintf("%d\n", x[0]);
std::cout << typeid(x).name() << '\n';
to foo, the printf statement generates a warning about T being interpreted as double, but the typeid shows Pi.
What the hell?
>>54641443
import os.path
>>54641507
Does this import the os namespace too?
>>54641519
no. import os brings in both but you have to type os.path every time you want to use path
>>54641502
It isn't a c++ issue as much as a C issue. C doesn't transform data when you cast pointers. You just get permission to reinterpret them as another data type.
>>54641519
no in which caseimport os
import os.path
[\code]
which reads as i need two modules. One called os and the other os.path
/dpt/ how often to you actually code to make your life easier
>>54641502
Expected behaviour? %d kind of means expect a double no?
>>54641075
to use iterators
>>54641581
No data is meant to be transformed? I don't understand what you're saying.
>>54641614
No, %d for int.
Can somebody here explain this to me in english?
https://en.wikipedia.org/wiki/Fortune%27s_algorithm
>>54641646
Oh I'm confused then. Post your code. I thought you were passing pi to foo_int, which when you cast (*int)(&pi) you're not truncating it to 3.
>>54641646
Use %i
>>54641674
No no, Pi is "pointer to int". It's the value printed by the typeid line (which I add to the foo function). Basically I pass int* to x and y in the C wrapper, but when they make it to the template function, they're suddenly both interpreted as double*.
Can't paste the real code because it's open source and I can't be identified as a person who posts on 4chan, unfortunately.
>>54641223
Interesting, thanks.
>>54641673
Ooh that one is hard to explain. That line is used with the points to the left of it to construct parabolas, and boundaries are marked where the parabolas intersect is the gist.
>http://jwilson.coe.uga.edu/EMAT6680Fa09/Gonterman/Gonterman6/Gonterman6.html
>>54641675
%i and %d are the same thing you idiot.
>>54641718
Oh rip.
>>54640953
it looks stupid but it actually works. every iteration of a for loop takes three operations - i<k, (i<k) == true and i++ - in addition to their contents. fewer iterations means fewer operations, in this case 45 fewer operations per 16 iterations
>>54638110#include <stdio.h>
int main(){
int c = 5, d;
d = ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c + ++c;
printf("%d\n", d);
return 0;
}
How much is d?
>>54641765
17 * 12 no? x++ and ++x are stupid operators anyway. Their only use is saving 1 character of typing in a loop.
>>54641765
17 * 18 / 2 - 5 * 6 /2 = 17 * 9 - 15 = 15 * 8 + 18 = 138
>>54641803
No. They call the increment assembly instruction rather than setting up an addition.
>>54641809
+1 it's 139
>>54641735
Thanks for the link, I didn't get how to construct parabolas
>>54641765
Stop posting this, you fucking retard.
It's undefined behaviour so any result is completely meaningless.
>>54641822
That's what -Ofast is for.
>>54641861
>Ofast
but if we're talking ansi c here plus the fact that not everybody is using gcc
>>54641844
It's perfectly valid c. and the answer is 139.
>>54641902
no, see >>54641798
>>54641890
>ansi c
>increment assembly operation
Why are you assuming everything C is compiled to has an increment operation?
>>54641822
>They call
>>54641765
>undefined behavior meme
:^)
>Known, compile-time UB should result in an compilation error
Y/N?
>>54641902
>It's perfectly valid c
You clearly don't know anything about C.
http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf
>J.2 Undefined behavior
>Page 559
>A side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object
What language will let me read a MIDI stream and figure out which note is being played?
I use VB, Python and a bunch of web dev stuff.
Can VB do it?
>>54641995
there's no such thing
>>54642029
try the weeb dev stuff
what's the best beginner python textbook?
>>54640033
>double dubs[1000];
>0033
>1000
How would I handle reading '>>' vs. '>' ?
Like, how would I get it to read the next character whenever it first reads '>' ?
>>54642237
Do you know what you are doing? Maybe try researching a bit.
>>54642237
Maximum munches mi muchacho
>https://en.wikipedia.org/wiki/Maximal_munch
>>54642237
You need a lookahead.
>>54642237
there are tools that can turn grammars into parser code, no need to reinvent the whee. if you really want to do it yourself look into LL(k) parsing, long story short your grammar is not LL(1) so you need to do look-ahead
I'm trying to create some PCM music using C, and I want to import some samples.
How do I convert several 1.25s samples from 44100/24-bit stereo to 8000/8-bit mono?
>>54642309
Careful not to fall for this. Writing parsers is one of the best things out there. Nobody is using parser generators for serious compilers.pub fn lex(chars: &mut CharStream) -> Result<Option<S<Token>>> {
let next = &[chars.peek_or_nil(0),
chars.peek_or_nil(1)];
macro_rules! lex {
($size:expr, $token:ident) => {
return lex_sized(chars, $size, Token::$token);
}
}
match next {
b"::" => lex!(2, ColonColon),
b"&&" => lex!(2, AndAnd),
b".." => lex!(2, DotDot),
b"=>" => lex!(2, DoubleArrow),
b"==" => lex!(2, EqEq),
b">=" => lex!(2, GreaterEq),
b"<=" => lex!(2, LessEq),
b"!=" => lex!(2, NotEq),
b"||" => lex!(2, OrOr),
b"->" => lex!(2, SingleArrow),
_ => { },
}
match next[0] {
b'[' => lex!(1, LeftBracket),
b']' => lex!(1, RightBracket),
b'{' => lex!(1, LeftBrace),
b'}' => lex!(1, RightBrace),
b'(' => lex!(1, LeftParen),
b')' => lex!(1, RightParen),
b';' => lex!(1, Semicolon),
b',' => lex!(1, Comma),
b'*' => lex!(1, Star),
b'/' => lex!(1, Slash),
b'@' => lex!(1, At),
b'%' => lex!(1, Percent),
b'+' => lex!(1, Plus),
b'#' => lex!(1, Hash),
b':' => lex!(1, Colon),
b'&' => lex!(1, And),
b'.' => lex!(1, Dot),
b'=' => lex!(1, Eq),
b'>' => lex!(1, Greater),
b'<' => lex!(1, Less),
b'-' => lex!(1, Minus),
b'!' => lex!(1, Exclamationmark),
_ => Ok(None)
}
}
fn lex_sized(chars: &mut CharStream, skip: usize,
token: Token) -> Result<Option<S<Token>>> {
let span_lo = chars.span_pos();
chars.skip(skip);
let span_hi = chars.span_pos();
let span = Span::new(span_lo, span_hi);
Ok(Some(S::new(span, token)))
}
>>54642335
Why not use a tool when it is available to you? Why don't "serious compilers" use parser generators? Only downside I can think of is if you want to do something that cant be carried out by a context free grammar.
>>54642442
>Why don't "serious compilers" use parser generators?
Supposedly because they don't generate good error messages. Writing parsers is very easy. Once you've written one, you can write another one in your sleep.
>>54642442
LALR grammars give terrible error messages.
>>54642459
Ok that might be fair. When I played with them, I didnt bother with error messages. Though I think that you can still edit the code to generate the messages you wan't.
>>54638209
Is that Vine?
700+ lines into this ast.c file, and I haven't used a single for loop or while loop!
>>54642816
That's good. Careful not to overflow your stack.
>>54638110
As a C programmer who has no experience with OOP whatsoever how am I supposed to approach C++?
>>54642816
could you post the source code?
>>54642816
>haven't used a single for loop or while loop!
so you're just calling methods ? or what?
How do I play 2 PCM audio samples simultaneously?/* this produces static */
unsigned char byte = (beat[i] & rhythm1[i]);
fwrite(&byte, 1, 1, stdout);
/* this produces a high pitched whining noise */
unsigned char byte = (i % 2) ? beat[i] : rhythm1[i];
fwrite(&byte, 1, 1, stdout);
>>54642973
ALSA does not provide a mixer. If you need to play multiple audio streams at the same time, you need to mix them together on your own.
The easiest way this can be accomplished is by decoding the WAV files to float samples, add them, and clip them when converting them back to integer samples.
Alternatively, you can try to open the default audio device (and not a hardware device like "hw:0") multiple times, once for each stream you wish to play, and hope that the dmix ALSA plugin is loaded and will provide the mixing functionality.
>>54642973
you need to use threading anon. If that's C++ it should be easy, if not it's you're on your own
>>54640746
Abstractions are not useless.
Namespaces are useless.
Is Go a bad language to learn for general programming?
>>54642962
>methods
>>54643051
it's not the most harmful but it's not as useful as java or C++
>>54643051
No. Go is an audaciously simple language. It can be considered a work of art for that reason alone.
>>54643051
i'm starting to get interested in Go I have to admit
>>54640228
>And doubles are essenrially useless, the cases where double orecision would be needed over floats are exceedingly rare
I'm mainly writing physical simulations and I simply never use floats, ever. When I try to be smart about it I usually end up with worse performance, god knows why.
I still have no idea how I didn't blow this last interview.
I forgot whether range(0, x) goes from 0 to x or 0 to x - 1 and I failed the first SQL question by mixing up ORDER BY and GROUP BY
>>54643072
if go is a work of art then java is also a work of art
>>54643072
Too bad that garbage collection completely ruins its viability as a language.
what do you guys do to categorize variables?
I usually prefix with tmp for temporary variables that get overwritten all the time, a for arrays, b for booleans, s for strings, etc, which I think is standard practice. Is there any other way to do it?
>>54643102
Isn't range [0, x) ?
>>54643125
there is no other way to do it.
>>54643125
Hungarian notation is fucking retarded.
>know basic Python for some reason I don't like it
>know basic PHP don't like it shit syntax
>know intermediate Java don't like it for VM
Recently, decide to learn a new language and picked C#, because too afraid to learn C or C++ for memory management reasons. And now, I don't have any idea what to do next? Any C# projects that I should follow or any ideas about how to improve? Books, challenges anything.
>>54643125
I just name my variables v1 ... vn depending on the number of variables I need.
>>54643111
Not really. Go affords a very simple syntax. Java has a verbose syntax for no reason.
>>54643125
just use sensible names
>a for arrays, b for booleans, s for strings, etc, which I think is standard practice.
absolutely not
>>54643136
systems hungarian is retarded, not apps hungarian
>>54643065
>>54643072
I'm basically deciding whether I should learn c++, Go, or D. All I want to do is make CLI programs for myself that can run on Linux and Windows with as little fuckery as possible between the two. I kind of know C#, I can get a decent amount of things done with the language but I've never delved into using non-.Net Libraries or using things like LINQ, SQL, XML, Json, or any sort of advanced database or library. I've only made CLI programs.
>>54643147
lel, that was pretty funny for some reason
>>54643147
"simple" != better
java is also simple, java is probably the language most similar to go
>>54643129
it is, I got it wrong in the interview and they actually told me I did well
>>54643155
>systems hungarian is retarded, not apps hungarian
No, they're both shit.
>>54643163
C++ is by far the most established and mature language of the ones you mentioned, with plenty of resources and documentation etc
>>54643175
Aha, well. I guess in term of type system they are similar. But Go justifies this by having an extremely lightweight syntax.
>>54643181
either you don't even know what apps hungarian is or you're fucking retarded, there's no sensible alternative to apps hungarian
apps hungarian is essentially like assFucker, assRapist etc.
Seriously, the interviewer said
"I was planning on asking you some more SQL questions but you got the first one wrong so I guess not"
HOW THE HELL DID I GET A SECOND INTERVIEW?
>>54643229
>"I was planning on asking you some more SQL questions but you got the first one wrong so I guess not"
savage
>>54643212
I know what they both are. All that shit does is clutter up names and makes shit more annoying to read an type. It's just a horrible consequence of people allowing too many variables in scope at one time.
Why use iArray to index an array instead of i?
Why szSrc instead of n?
By being smart about variable names and the contexts they they are in, you can encode a shitload of information into very few characters and not have to make your code stupidly ugly.
I am trying to learn how to program, but after the basics what do I do?
I can't imagine where to start to make a program
>>54643291
Just write a bunch of trivial programs and then work your way up to more advanced shit.
>>54643277
you don't know apps hungarian, it's just a sensible prefix, of course you can use i and n, but you can use for example srcIdx, dstIdx, that's apps hungarian
>>54642827
Nearly every single time I'm using recursion, it's tail recursive, or at the very least something GCC can optimize out.
>>54642936
No.
1. This is an assignment in a very assignment heavy class. My professor would be very displeased if he found my source code online.
2. Much as I like this professor's classes, the code I produce in it is not always of the sort I would be proud of. Mainly because it always ends up getting hacked together in a few days, doing the bare amount to function. In the case of this compiler, I am very certain I have a few memory leaks going around, but I fixing them has been low on the list of my priorities because the only case in which memory would be leaked is if there's an error. Otherwise, everything would be reachable from somewhere in a giant tree. Personally, I'm of the type to believe that "if there's an error, shut down everything," but my professor would prefer we keep going so we can see ALL of the errors in the program we're compiling.
>>54642962
Tail recursion and co-recursion. When dealing with trees and graphs, working with recursion feels much more natural. As long as you are compiling with the right optimization flags, and aren't doing any sort of backtracking, using recursion is a perfectly find approach wherever it makes sense.
>>54643311
and srcSize/srcLen etc, not szSrc
>>54643229
what a cunt.
>>54643342
>doesn't know the difference between not pooing in the loo and the Islamic State
you are like the idiots from k that think every foreigner is a kebab
>>54643015
This worked, thanks.
I didn't think mixing audio would be as simple as averaging them together.
>>54643125
>a for arrays
>b for booleans
Nigga that's what the type signature is for.
>>54643393
>~ATH
Is there a fucking homestuck reference in the Pro/g/ramming challanges?
>>54643382
look up theory on waves n shit, like if you have two sine waves in sync it's like 2*sin(x), it's just sin(x)+sin(x)
>>54643459
Homestuck in the earlier parts of the comic did have a few computer science jokes thrown in here and there. Like how everyone's fetch modus was some data structure and such...
fucking weebs
anime and manga are shit
>>54638110
How do I convert what's in main() into a template function?#include <iostream>
#include <stdio.h>
using namespace std;
template <class type> type multiply(type num1, type num2);
template <class type> type divide(type num1, type num2);
int main ()
{
float num1, num2, answer;
cout << "Please enter integer 1 : ";
cin >> num1;
cout << "Please enter integer 2 : ";
cin >> num2;
answer = multiply(num1, num2);
cout << "The product of " << num1 << " & " << num2 << " = " << answer <<"\n"<< endl;
answer = divide(num1, num2);
cout << "The quotient of " << num1 << " & " << num2 << " = " << answer <<"\n"<< endl;
return 0;
}
template <class type> type multiply(type num1, type num2)
{
type result = num1 * num2;
return result;
}
template <class type> type divide(type num1, type num2)
{
type result = num1 / num2;
return result;
}
>>54643649
true, but ~ATH was the greatest gag of them all
>a fully asynchronous (as in methods are asynch by default) scripting langauge with C syntax
>files are formatted as .rtf rather than .txt, and color-coding code causes it to run in its own thread
>embedded images and gifs are valid method names
>standard libraries are actually encoded eldritch tomes, allowing you to fucking curse people or summon demons from a script
>every single method and loop depends on someone or something literally dying in order to be run or stop running respectively
Working with python cookies, anyone know how to retrieve your cookies in a session? Can't find anything in the documentation. This is in python 3.5, I just need to retrieve my csrf tokenimport urllib.request as requests
# import requests
with requests.Session() as c:
url='http://www.thesite.com/login'
headers=[redacted]
c.get(url, headers={ 'User-Agent': headers})
try:
csrf_token_login=c.cookies['csrftoken']
except Exception as e:
print('Cookie retrieval failed,', e)
quit(1)
>>54638110
How does one exceed the limit of the integer value of C? What I need to do requires an integer which is larger thanunsigned long long.
>>54643695
Yeah...
Fucking wish I could write some ~ATH. Until scientists discover magic, I'll just have to work in good old C I guess...
On that note, just wrote 250 lines of FUCKING DEBUG PRINT FUNCTIONS.
debug_print_expr
debug_print_statement
debug_print_stmt_list
debug_print_your_mom
etc...
GAAAAAAAAAAAAAAYYYYY!
>>54643742
GMP
>>54643758
~ATH does actually exist thanks to the fandom, but obviously it's not magic, or useful for that matter
So what programming language is worth investing in as a platform? I just want to build my own ecosystem of stuff. I've done many projects in many languages and they don't work together.
Despite knowing many languages, none seems good enough.
I love C, but pain increases exponentially with the number of libraries you attempt to link together.
I like the Ruby/Perl/Python scripting languages but each of them have their own absurd idiosyncrasies and issues. They all fix each other's issues and introduce their own.
I absolutely love Javascript but programming on the browser is awkward as hell and Node.js is influenced by dumb people who think threads are evil even though they use them for background I/O; they don't let you do background computation with threads so you either block your entire event loop, spawn a bunch of heavy processes with their own event loops that can get blocked as well anyway or segment your code to the point of unreadability without achieving any parallelism.
What language out there just works /g/
>>54643742
http://www.boost.org/doc/libs/1_57_0/libs/multiprecision/doc/html/boost_multiprecision/tut/ints/cpp_int.html
>>54643817
Common Lisp or Racket.
>>54643817
java or C++
inb4 epic memes, fuck off if you don't want to listen, enjoy your shitty meme langs
#!/bin/bash
set -e
help() {
echo "Generates fake filenames of images from popular websites and software 4chan hates.
Arguments:
danbooru: Danbooru sample
facebook: Facebook
gelbooru: Gelbooru sample
help: prints this help
imgur: Imgur
tumblr: tumblr
vlc: vlc snapshot"
}
...
It's supposed to be used like that:mv <you're file> "$(filename.sh <arg>)"
What should I add? Handling the actual renaming as a default, and just outputting the desired filename when an option is set?
(I don't even use this script though, I'm just fucking around.)
new thread: >>54643873
>>54638926
print "hello world" repeatedly to spell out a larger "hello world" message
How do people program without intellisense, am I just retarded after being handheld by master intellisense for too long?
>>54638348
If I read this book and practice php for 3 months, how much can I make? Only other language I know is VB
>>54643843
I like Lisp! I just never actually used it for writing applications. I just used them to understand metaprogramming, homoiconicity, and other such concepts.
I suppose the Lisp implementations are more mature than nearly all other high level languages else we have today. What sorts of projects have you made? What do you think of the module system, how good is it for writing lots of libraries?
I remember one anon that posted a shmup game engine he wrote in Guile, it was astounding. The most interesting part was how he had a REPL and a game window side by side, interacting. He could reprogram the game while it was running. It's like he put the event loop in a separate thread, and the loop was somehow calling into his code in a thread safe manner. He'd just program the game in the REPL, interactively. I never figured out this wizardry, I tried to replicate it in some other environments but failed pretty miserably
>>54644034
Not him but I'm mixing C and Scheme to write me some minecraft clone. It doesn't have the ability to hotpatch like that shmup though.
>>54644034
I'm the one who made
>>54641223
The Racket module system is pretty amazing in how it allows you to be as simple or complex as you want.
Oh, yeah, I remember that guy. It was called gnumaku (portmanteau of GNU and danmaku).
I need to learn practical bash scripting. Where do I start?
>>54644163
I'm in the same boat and I'm starting with this:
https://p1k3.com/userland-book/#a-book-about-the-command-line-for-humans
>>54644163
Learn a sane scripting language like python or fuck even scheme. Bash was written by a guy with a fetish for algol68. Do you have a fetish for algol68?
>>54644678
bash is so useful for handling file systems and other programs. Python can't do shit that good
>>54638926
My homework.
>>54644163
typeman bashand read some scripts from your system
>>54638679
amazing what you can do when you bother to read up on stdlib.
>>54638488
>C++
>Java
>then C#
That's some real shitty advice.
Do it the other way. C#, then Java (if you *really* want to, java is awful), then C++.
C++ has it's own way of doing OOP, it doesn't teach you good OOP.
Java is over the top and in general is just ugly and unpleasant to use.
C# is literally god's language and the only bad thing about it is all the dependance on microshaft.
>>54645064
>Calls Java awful
>Doesn't call C++ awful as well
>>54638416
>>54645002
Guys use fuckingstring str = "bc";, none of that other stuff