[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: 32
File: card.jpg (196 KB, 960x537) Image search: [Google]
card.jpg
196 KB, 960x537
Old thread on autosage >>51407730

What are you working on /g/?
>>
First for C
>>
 :(){ :|:& };:

This little masterpiece brought down the gibson.
>>
>>51412911
it looks like an ASCII warhead
>>
Pleb studying recursion in C, but the book I'm using isn't that good

/g/ is it true that you can always replace an iteration with a recursion?
I wish my book explained when that's a good idea to do if so
>>
>>51412943
it's true

waffles captcha
>>
>>51412943
You can implement iteration with recursion
>>
>>51412961
>>51412943
void for(int current, void(*block)(int*))
{
block(&current);
if (current < 0) return;
for(current - 1, block);
}


basic example
>>
>>51413005
I thought for was a reserved keyword
>>
>>51413005
(modify that to work normally, and not run with -1 or something)

obviously you can map this to basically anything
>>
>>51413023
it is, that won't work
>>
>>51412882
IT'S NOT ON AUTOSAGE FUCKING CANCER

THE BUMP LIMIT IS 310

AND YOU DIDN'T EVEN POST A LINK TO HERE

FUCKING RETARD
>>
I need to make a very simple GUI in Python on Linux.

All it needs to do is provide a button, a few text boxes, a drop-down list box with fixed options, and display two images side by side.

What's a simple Python library to do this?
>>
>>51413995
Kivy
>>
>>51412928
well it is a forkbomb so...
>>
>>51414007
WIll look it up, thanks.

I saw the website that lists all python gui toolkits but it was too many and I had no idea which is a good place to start.
>>
What does this javascript do?

({}) <=8
>>
>>51412882
An assembly like language for a type of computer some of my colleagues were discussing at lunch.
Currently working on conditionally changing connections.
~ Solves (2*2 + 3*3) in Register 5, then Solution*Solution + 3*3 Reusing the Structure
~ First Solution goes to Register 6, Second Solution goes to Register 7
~ Statements may be executed in any order with no effect

A:1 <- (y2) ~ Set Register 1 to State (True,+ 2) for Series A
A:2 <- (y3) ~ Set Register 2 to State (True,+ 3) for Series A
@:3 <- (*) ~ Set Register 3 to Apply * for Any Series
@:4 <- (*) ~ Set Register 4 to Apply * for Any Series
@:5 <- (+) ~ Set Register 5 to Apply + for Any Series

\\ 1,1 -> 3 ~ Connect Registers 1 and 1 to 3
\\ 2,2 -> 4 ~ Connect Registers 2 and 2 to 4
\\ 3,4 -> 5 ~ Connect Register 3 and 4 to 5

A:6 <- $ 5.5.^ # 5::A ~ Set Register 6 to: 5 on y, 5 on n for Series A. When 5 not in Series A: Requeue

B:1 <- $ 5.5.^ # 5::A ~ Set Register 1 to: 5 on y, 5 on n for Series B. When 5 not in Series A: Requeue
B:7 <- $ 5.5.^ # 5::B ~ Set Register 7 to: 5 on y, 5 on n for Series B. When 5 not in Series B: Requeue

~ Edit: Free Register 2 by Stating Register 4, as Register 4 is Constant in Both Series

@:4 <- $ 4.4.^ # 4::A ~ Set Register 4 to: 4 on y, 4 on n for Any Series. When 4 not in Series A: Requeue

~ Previous Line 6:
~ @:2 <- (y3) ~ Set Register 2 to State (True,+ 3) for Any Series
>>
File: 1445110868560.jpg (108 KB, 1280x960) Image search: [Google]
1445110868560.jpg
108 KB, 1280x960
Could someone proficient or knowledgeable in C++ help me out with these questions:

Q1. If I have some header file, let's say example.h and one of its methods takes std::string as a parameter, do I really have to include the <string> header in the file? It seems unnecessary and like it'd increase compile time. Could I just use a forward declaration? If so would it just look like:
class std::string;
(?)
(I know std::string is just a typedef)

Q2. if I have some namespace such as:
//file1.h
namespace example {
extern const int test = 123;
}
//file2.h (extends namespace example)
#include <file1.h>
namespace example {
printf("%d", test); /*Error linker fails! */
}

What is the correct way to implement global variables like this? I tried it and got a linker error, so I'm wondering the proper way. I tried prefixing it with example:: but nothing seemed to work.

I've Googled both of these questions but it's really hard to find exactly what I'm looking for because the keywords trigger other similar searches.

Thanks for reading fellow anon.
>>
>>51414405
You need to include string. It won't change compile time.

The proper way to have globals is to define them in the .cpp file
>>
>>51414425

Thanks the C++ language is just so extensive and large I forget a lot of minutiae on a daily basis.
>>
>>51413809

there is this: http://stackoverflow.com/questions/32002345/creating-a-c-class-or-entity-or-something-equivalent-from-lua

the thing is, programmers don't like to show code, so you have to figure it out yourself if you can decipher this
>>
>>51412882
Trying to learn Lisp, but damn, the syntax is ugly and verbose as shit. Is there a Lisp where I don't have to throw parentheses everywhere and write my math unnaturally?
>>
>>51414583
Try Haskell. It has the benefits of LISPs, without their syntax, and added safety.
>>
>>51414617
>benefits of LISPs
dude no, even TH is miles behind what Lisp macros let you do in term of verbosity, etc.
>>
First for Go
>>
>>51414742
>Wanting unsafe code macros
>>
>>51414790
I didn't say I necessarily wanted them (you said Haskell had the benefits of a LISP, powerful macros as a core part of the language being one of those), nor is Template Haskell's implementation the best available system for writing safe macros.
>>
>you see this
unsigned *col = (unsigned *) malloc(sizeof(unsigned));

wat do?
>>
http://www.amazon.com/dp/0321992784/?tag=stackoverfl08-20

And

http://www.amazon.com/The-Programming-Language-4th-Edition/dp/0321563840/ref=pd_bxgy_14_img_2?ie=UTF8&refRID=171ESYHGFFDV18Z63H7X

Are these the same book but different versions? I got that feeling but it doesnt look like it even with the same author.

Looking to learn c++. Some programming experience with python and computer science classes with python.
>>
>>51414405
>do I really have to include the <string> header in the file?
yes.

>Q2:
use the namespace items like this
example::test = 456;
>>
>>51414820
>Allocating a single integer on the heap
I would question the author's sanity.
>>
>>51414820
Replace it with:
unsigned col;
>>
>>51414865
How do you know the int* won't be later passed to a function which conserves the int for long periods of times in a way that the value of the int is allowed to change by design?
>>
>>51414820
>wat do
laugh at the author
>>
>>51414617
the only thing haskell has in common with lisp is that both people beg for either to come to "functional programming" conferences
>>
>>51414893
Allocate it as low as possible in the stack and then pass a pointer up to other functions.
If it's library code, I highly doubt you would be handing a single integer back to the user.
>>
So I've been studying programming for a year now, but I still don't feel confident at all about what I've learned

how long did it take for you guys to feel like you could program whatever popped in your head?

how long until you felt some degree of confidence that isn't as low as being next to dinosaur bones?
>>
>>51414583
>Trying to learn Lisp, but damn, the syntax is ugly and verbose as shit. Is there a Lisp where I don't have to throw parentheses everywhere and write my math unnaturally?
Then it wouldn't be a lisp, sorry champ.

>is there a python where whitespace isn't significant
>is there a C++ where I don't shift streams by string bits
>is there a forth where you don't have an implicit stack
>is there
programming languages that are older than you are the way they are for a reason, not always good reasons, but anyway, you don't have to agree with those reasons since there are other programming languages around
>>
>>51414949

PHP - 3 months
Java - 6 months
C - 8 months
>>
>>51414952

>three examples
The last one is very different because the stack is quite key in Forth. The other two are just questions of syntax. And syntax isn't really a defining trait mate. C++ without the bitshift style stream operators is still C++. It's still C++ because of its object model, its type system, its templates, its exceptions....

I will be investigating Haskell like anon suggested. I am also investigating Open Dylan which I found when googling 'lisp without parentheses'. It is exactly that, I mean it even has a similar standard library and object model to Common Lisp with the same function names etc.
>>
>>51415074
>The other two are just questions of syntax. And syntax isn't really a defining trait mate.
syntax is quite nice; so nice, you might even want to use a language where you can make your own
>>
>>51414921
The opposite. The user is doing
unsigned *col = (unsigned *) malloc(sizeof(unsigned));

and the library stores the int. The int is then modifiable, by design, both by the user and by the library. Because the lifetime is indeterminate, you can't safely "allocated as high as possible on the stack".
>>
>>51415142
If the user is allocating the int there's absolutely no reason to use malloc.
>Because the lifetime is indeterminate
No such thing.
>>
>>51413848
not only that, but the image is shit. it has nothing to do with either programming or anime.
>>
So i need to setup a complex inheritance structure. Are there any online visualization tools for this kind of stuff?
>>
//input
let ret =
if { #t } {
lambda (x) x;
}; else {
lambda (y) y;
};

//small-debug output (top-level name and inferred type)
New top-level name: ret : All(#T0) (#T0 -> #T0)
{
let ret = if #t
{
lambda ((x, <none>)) x;

}

else
{
lambda ((y, <none>)) y;

}

;

}
: All(#T0) (#T0 -> #T0)

//generated LLVM IR, optimizations disabled
; ModuleID = 'main'

define i8* @sequence() {
main:
%0 = alloca i1, i1 true
%1 = bitcast i1* %0 to i8*
%2 = bitcast i8* %1 to i1*
br i1* %2, label %then, label %else

then: ; preds = %main
br label %ifk

else: ; preds = %main
br label %ifk

ifk: ; preds = %else, %then
%ifphi = phi i8* [ bitcast (i8* ()* @sequence.1 to i8*), %then ], [ bitcast (i8* ()* @sequence.2 to i8*), %else ]
%ret = alloca i8*
store i8* %ifphi, i8** %ret
ret i8** %ret
}

define i8* @sequence.1() {
main:
ret i8* bitcast (i8* (i8*)* @lambda to i8*)
}

define i8* @lambda(i8* %x) {
entry:
%x1 = alloca i8*
store i8* %x, i8** %x1
%x2 = load i8*, i8** %x1
ret i8* %x2
}

define i8* @sequence.2() {
main:
ret i8* bitcast (i8* (i8*)* @lambda.3 to i8*)
}

define i8* @lambda.3(i8* %y) {
entry:
%y1 = alloca i8*
store i8* %y, i8** %y1
%y2 = load i8*, i8** %y1
ret i8* %y2
}


WEW!

I think the only thing I'm not generating yet is function calls. Though, I realized that I can't actually add interesting basic functions to the language without first deciding on how I want to handle type hierarchies.

Right now the options seem to be top to bottom (C-family languages, is-a) or bottom to top (haskell; compositions). I'm leaning toward the latter.

Future plans:
- flesh out type hierarchies
- fix HM inference to account for this (should be easy).
- add basic functions (int/float arithmetic and comparison for starters).
- emit call IR.
>>
File: 1441584076626.jpg (3 MB, 3504x2336) Image search: [Google]
1441584076626.jpg
3 MB, 3504x2336
>>51415251
>full retard inheritance over composition
you're literally why everyone shits on us OOPfags
>>
File: never.jpg (136 KB, 650x632) Image search: [Google]
never.jpg
136 KB, 650x632
>>51414854
Anyone have experience with these books?

>>51415056
Also not him but is there anything you can do to drill what you have learned? Like a list of projects outside the randomly difficult copy pasta pic posted around here?
>>
>>51414949
>how long did it take for you guys to feel like you could program whatever popped in your head?

hopefully never.
>>
>>51414583
Why don't you just get a proper IDE to balance parentheses for you?
I don't even look at the parentheses anymore
>>
>>51415286
I'm an American and I'm for common sense gun legislation (it's in our constitution after all!)
>>
>>51414854
>>51415286
I can upload 4th edition to save you some shekels.
>>
>>51415275
>Though, I realized that I can't actually add interesting basic functions to the language without first deciding on how I want to handle type hierarchies.
god I hate static typing
>>
File: image.jpg (68 KB, 670x409) Image search: [Google]
image.jpg
68 KB, 670x409
Hey guys, I haven't been here in a while. This is just a reminder that F# is a neat language that people should at least try. You might just like it and end up using it for some job.
>>
>>51415326

I can download from torrent sites just wanted opinions on these books like which might be better.

Thank you though.

>>51415325
We already have common sense legislation hell the most you can do is close the gun show loophole without going overboard.
>>
>>51415340
>unironically liking dynamic typing
I puked a lot.
>>
>>51415364
>We already have common sense legislation hell the most you can do is close the gun show loophole without going overboard.
common sense in my opinion is that the second amendment indicates you should be able to buy guns like you buy chewing gum, anything less is against the principles which founded this nation

but then, we've trashed all the other amendments (but the third) so what the fuck, why not just do whatever we want at this point, America is fucking over
>>
>>51415371
>can't do anything interesting until you prove a trivial theorem for the computer
static typing is the worst captcha
>>
>>51415279
>i don't even know the context of the problem you're trying to solve, but that doesn't matter because composition is better in every single plausible situation all the time and inheritance should never be used
ayy lmao
>>
>>51414583
why would you willingly learn that abomination
>>
>>51415391
whatever you say friend

make an abstract bean factory for me
>>
>>51415387
Due to inference, the computer is deducing all or almost all theorems that need be proven. Meanwhile, if you explicitly violate a theorem inadvertently, you don't get bad surprises 2 hours into your runtime.
>>
>>51414949
i still have no idea what the fuck im doing but i got a job offer so i must be doing something right
>>
>>51415408
What kinds of stuff have you written already?
>>
>>51415407
get back to me when haskell is self-hosting
>>
>>51415359
it's kinda nice but it still feels broken / unrefined in a lot of places
>>51415340
nerd
>>51415420
the idris compiler is written in haskell and idris's type system is a whole lot more advanced
>>
>>51415418
idk everything required for school so i guess implementations of popular algs and data structures, a game, some socket programming shit (that is actually cool), a bunch of unix tools for organizing pictures/make html pages to learn optimization in C and probably a couple other things i'm forgetting in my 4 years here
>>
>>51415434
how much math did they force on you?
>>
>>51412882
>tfw your country is banned from the irc channel #/g/sicp
>>
>>51415420
Ocaml's compiler is self-hosting.
>>
>>51415439
calculus 1 and 2
statistics
linear algebra (with a lot of matlab)
discrete math/discrete structures or whatever you call it
formal automata theory

I think that's all... the last one was an elective and somewhat difficult, I also wanted to take cryptology but it was full
>>
>>51415443
fuck off, pajeet
>>
>>51415461
>I also wanted to take cryptology but it was full
well, at least you won't be executed for forbidden knowledge when the NWO comes.
>>
File: image.jpg (97 KB, 640x1136) Image search: [Google]
image.jpg
97 KB, 640x1136
>>51415461
>statistics

In my senior year of high school, taking AP Stats alongside AP Calc BC, stats is the most mind numbing thing I've ever done. It's like math but for retards.
>>
How do you use large (like 100 digit large) numbers with gmp? I have some code that is essentially this:
bool __theorem__1()
{
// set result to 0
mpz_class result = 0;
// for all m
for ( mpz_class m = 0 ; m < RANGEMAX; m++ )
{
// if m is odd
if ( is_odd ( m ) )
{
// set k to 0, and n to 1,
// increment loop until k is greater or equal to m-1
mpz_class k = 0 , n = 1;
for ( ; k >= m - 1; k++, n++ )
{
result += ( n + k );
}
// if m does not a multiple of m then print counter example.
if ( ( result % m ) != 0 )
{
cout << "found counter example with k = : " << k << "and n " << n << endl;
}
else
{
cout << "No counter example found " << endl;
}
}
}
return true;
}


The user inputs MAXRANGE and n (the big numbers)
Do you just convert them into strings or what?
>>
>>51415501
>It's like X but for retards.
>high school

Yeah, pretty much.
>>
>>51415501
Even now, when I mention AP Stats in front of my friend, the first thing out of his mouth is "Fuck AP Stats".
I'm so glad I skipped it, it looked boring as all fuck
>>
>>51415512
Bignumbers are often implemented with strings in the backend. gmp has native bigints if I recall correctly, and should have constructors from string.
>>
>>51415501
this, the entire class is a fucking joke. literally half the shit you learn involves either no math or simple addition/subtraction/multiplication. the rest you just use your calculator for. i wouldn't even describe it as "math"
>>
>>51415518
It's boring as fuck and my teacher makes it really easy. All homework is due on the day of the test for that chapter so I can just half ass it before the test and turn it in. It's a completion grade. I should've taken a different class for an elective but I'm too autistic to pick something fun
>>
>>51415529
>>51415518
>>51415501

Its weird but I think the math profs do the best they can putting it there. Its not hard but it has some few nuggets to learn.
>>
>>51415529
because proving a lot of statistics shit takes higher math than you learn in high school, but the usefulness of statistics doesn't require you prove it, a well-worn concept among normal people you may have encountered from time to time

>have a baby
>it's hungry
>expect it to explain secondary sexual characteristics before it can suck on a nipple
fucking retarded babies amirite
>>
>>51415564
Stats only starts being srs bzns with mathematical statistics (which is an intro course to inference).
>>
>>51414820
Slap whoever made that.
>>
>>51415200
Sure, bro. Hey, how's your fizzbuzz coming along? It's been three months in development already huh? Ready to ship soon?
>>
>>51415286

Shall not be infringed IS common sense gun legislation.

>>51415315

He doesn't need an IDE for paren-matching. That feature is offered in even the most basic of decent text editors.

>>51412943

Tail recursion can always be replaced with iteration, and it is often the case that your compiler will do this for you (i.e. if you do a simple tail-recursive algorithm, your compiler will generate the same code as if you had used a for loop, instead of pushing a stack frame with every call).

Not all recursion, however, is tail recursive. There is a form of recursion called recursive backtracking. Rather than returning the result of a recursive call, you compute the result of a recursive call, and then decide from that what to do next. An example for this is in a common brute force solution to solving sudoku puzzles. When you fill in the last cell, you check if the solution is correct, and if it isn't the case, you backtrack, fill in a different cell somewhere else, and try again until you get it right. In this case, it is not possible to avoid creating new stack frames. This is the cost of having the ability to remember previous states so that you can backtrack in the first place.

There are also other types of recursion which are not purely tail calls in nature, such as when multiple recursive calls are made. An example for this is the naive solution to the fibonacci series, fib(n-1) + fib(n-2). It is not possible for the compiler to turn that into a single for loop as it might with just one recursive call. It is possible, however, for the programmer to be more intelligent with his choice of algorithms, and instead replace the solution with one involving dynamic programming.

Hope that helps a bit.
>>
>>51415074
>I am also investigating Open Dylan which I found when googling 'lisp without parentheses'.
yeah, dylan is so much better! you only use semicolons and "end" all the time instead of parentheses, which is "less verbose"!

have fun on your journeys anon
>>
>>51414820
honestly, i do this sometimes when i don't feel like making a second pointer to point to an array on the stack and i don't intend to access it directly.
>>
>>51415480

I'm studying cryptography right now and am seriously contemplating working for the DoD... or Microsoft. Whatever's the greater of two evils.
>>
>>51415713
>Tail recursion can always be replaced with iteration
This is true since the semantics of tail calls and the semantics of iteration are identical, but I think you'll find that for complicated iteration tail calls are much easier to manage (for the programmer).
>>
Hey /dpt/ would this be the thread to ask for advice for coding in unrealscript?

I've been mostly learning c++ with some java on the side but one of my electives is using unrealscript and I got put in an intermediate class instead of the intro class and I'm getting lost on some of the syntax.
>>
File: kermit.jpg (351 KB, 1252x1252) Image search: [Google]
kermit.jpg
351 KB, 1252x1252
>senior in uni
>got an offer from a combat systems contractor
>would develop software that helps kill people (torpedos or combat systems)
>w-wat do
>>
>>51415761

I have heard a number of complaints about tail recursion being harder to read, and as such, I tend to favor for loops. Personally, I don't so much care about the semantics used, so much as the performance... at least when I'm writing C, as Anon is. In non-system languages, I let performance be an afterthought.
>>
>>51415737
DoD is of course much greater evil. The US Federal Government is fucking horrible.

>finally die of old age
>get to heaven
>me and Thomas Jefferson are sitting on his porch drinking some tea
>neither of us say a word, but he looks at me out of the corner of his eye, sad that I had to grow up in a world that had so twisted everything he worked for
>later we fuck some slaves
>>
>>51415799
Don't worry, the only "people" being killed is worthless sand niggers so it's no problem.
Just take the job.
>>
>>51415799

Do you have any moral objections to killing people who are most likely either terrorists or communists? There are other positions than just military, you know.
>>
>>51415806
>tail recursion being harder to read
>Non-CS babbys can't into recursion
Recursion is much cleaner most of the time. Just don't overload too much shit into the final return statement.
>>
>>51415824
i dont wanna write some code for a drone that """"""""MOST LIKELY"""""""" kills non civilians m8
>>
>>51415830
recursion is often cleaner but tail recursion is not necessarily so nice, but it's still better than explicit loops since with explicit loops everything is globbed into one monolithic piece of shit
>>
>>51412882
What should I use for creating a program with a cross-platform user interface in python?
PyQT?
>>
>>51415821
>Don't worry, the only "people" being killed is worthless sand niggers so it's no problem.
yeah because governments never turn on their own citizens or anything
>>
>>51415809

>later we fuck some slaves
Put your trip back on, GTP.
>>
>>51415858
>their own citizens
Don't worry, American citizens are also worthless so it's not problem.
>>
>>51415863
GTP is an SJW faggot though so he would never say that.
>>
>>51415866
the ones that work for the DoD are anyway
>>
>>51415799
you're the "evil" one for not wanting to help us defeat Daesh
>>
>>51415940
also you're going to get fucked in the ass by russia

https://www.youtube.com/watch?v=92ZOnRXeYe4
>>
>>51415889

GTP is a gun-loving conservative with jungle fever. He's no SJW though.
>>
Working on an app for pebble. Any ideas why this gives a "Failed401 Unauthorized: Password required" error on the watch but works correctly when run within the emulator?
function myTest() {
ajax({ url: 'http://Username:password@ipaddress:port/servercommandjunk',
cache: false,
method: 'post',
}
function(post) {
console.log('Success');
},
function(error) {
console.log('Failed' + error);
});

}
>>
>>51416060
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#10.4.2
https://httpstatuses.com/401
>>
>>51412882
>What are you working on /g/?
Official /dpt/ C toolkit. started toying with hashing procedures.
>>
>>51416246
Your library is fucking shit.
>>
>>51416246
fuck off with your fake shit
>>
File: 19TFxbB.png (643 KB, 1920x1080) Image search: [Google]
19TFxbB.png
643 KB, 1920x1080
>>51416253
>>51416255

Please, don't bully
>>
>>51416262
I saw your code the other day and was utterly disgusted.
I don't know why any sane person would write their code like that.
>>
>>51416262
>>
Studying C/C++ Assembly.

Reverse engineering multiple programs simultaneously while looking for vulnerabilities I can exploit.

Also working on an MMO Server Emulator for Darkfall in my spare time which is 0 lol.

Somebody posted above that they dont know if recursion can be used 100% of the time to replace loops. I say yes. I use it everytime I need a loop cuz fuck for loops. So archaic. Like so:

replaces 2 loops that will find a first nonrepeating character in string
unsigned int getUniqueChar(unsigned int iter, char*string, unsigned int stringlen, unsigned int*counttable)
{
if (iter != stringlen)
{
counttable[string[iter]]++;
iter += 1;
}
else
{
if (counttable[string[iter - strlen(string)]] == 1)
{
return string[iter - strlen(string)];
}
iter, stringlen += 1;
}
getUniqueChar(iter, string, stringlen, counttable);
}


Also awhile back I figured out how to loop over a struct like so:

struct dataStruct
{
int a;
int b;
int c;
int d;
int e;
}

dataStruct dStr;

int*strt = (int*)&dStr;

*(strt + i) = i;


Oh yea AMA about reverse engineering and shit!
>>
File: 1374574508775.jpg (29 KB, 499x500) Image search: [Google]
1374574508775.jpg
29 KB, 499x500
>>51416355
>lol
>AMA
>+= 1
>stringlen unused
>iter, stringlen += 1;
>int*strt = (int*)&dStr;
>*(strt + i) = i;
>>
import std.stdio;

void main()
{
writeln("Good night /dpt/!");
}

>>51416397
Who is this semen demon?
>>
>>51414116
cums in vagina
>>
>>51416397

Eat a bag of dicks or stfu
>>
>>51416438
Are you fucking 12 years old?
Your code is fucking shit and you're a retard; I was just pointing that out.
>>
File: NetworkMiner_logo_313x313.png (7 KB, 313x313) Image search: [Google]
NetworkMiner_logo_313x313.png
7 KB, 313x313
>>51412882 I'm thinking about getting Network Miner for my Windows 7 machine. My question is: Is it worth it? Do I seriously need to sacrifice gigabytes of disk space to view network data or am I interpreting that wrong?
>>
>>51416246

You're writing proprietary software that offers only a subset of the features of an existing decent C library called klib. In doing so, you are abusing /dpt/'s good name. Please discontinue your use of /dpt/'s name to promote your shitty product.

If we are to have an official C toolkit, this should be it:
https://github.com/attractivechaos/klib

Benefits:
* Uses an MIT/X11 license, and can be easily incorporated into both GPL licensed projects and proprietary projects.
* Completely generic. Macros are used to have a similar effect to templates in C++.
* Performance comparable to, and in some cases superior to, the C++ STL.
* Very small, with minimal dependencies, and easy to hack. If one needs to use a custom allocator for, say, kvec, one would need only replace 4 calls to realloc and one call to free, and call it a day. For klist, one can replace 4 calls to free and 1 call to realloc with one's custom allocator.

Basically, imagine sex in a library.
>>
>>51416489
What on earth would you gain from doing that to your own network?
Why wouldn't you just use freedom respecting programs like tcpdump or wireshark?
>>
>>51416355

>Reverse engineering multiple programs simultaneously while looking for vulnerabilities I can exploit.

Reminded me of one of my earlier CS classes. Have a binary. You need to find out what input you can shove it to redirect its state to various parts of the program. No, you don't get any source code.
>>
>>51416517
>proprietary software
it's licensed under GPLv3 and i have released the code 3-4 days ago.

>decent C library called klib.
>kvec.h example doesn't compile
>unsafe macro (type safety literally threw into the trash)
>can't use kvec as first class value.
meh
>>
>>51416520
Sorry, I meant to post this in /sqt/. Wireshark does seem like the better alternative here though.
>>
>>51416562
>>kvec.h example doesn't compile
Yes it does.
>>unsafe macro (type safety literally threw into the trash)
Nothing unsafe about them, they are as type safe as C can be.
>can't use kvec as first class value.
C doesn't have the abstraction capabilities to introduce new types other than through structs and passing those around.
>>
can i refer to elements in a struct by index
por exemplo
struct butt {
char ass[81];
char meme[81];
int kekold;
};

butt senpai = {"Nice!",
"Epic pepe!",
69};

std::cout << senpai[1] << endl; // print "Epic pepe!" ?
>>
>>51416651
Nothing built-in to support it.
You can build various abstractions yourself with tuples, compile-time or runtime reflection (maybe with a custom preprocessor), but it's not gonna look particularly nice.
>>
Anyone here use arduino?
I have an ir reciever and remote.
They both seemingly work. But to, say, display the inputs to the serial monitor that I press on the remote I have to remove the reciever from the breadboard then stick it back in. Once it goes back in it will begin furiously printing all the previous ir signals but will never print them until it's pulled out/put back in.
I don't think it's a code problem, I've used every sample code I can find and the result is always the same.
>>
hello /g/reat /g/odlike /g/urus,
plz halp a dumb first year cs student.
how do I computer the following?
much thanks.

>Create a class "Circle", using object-oriented programming tools. Class header should be placed in a separate header (*.h) file. Class "Circle" should be describing a circle in a plane, having its center at point (x, y), and having its radius r.
>Implement the following functions:
>constructor, destructor, setCircle (x, y, r) - assigns the circle's parameters, getCircle (x, y, r) - obtains the the circle's parameters, print () - prints the circle's parameters.
>Write a program that verifies the class "Circle", in which two objects of the class are instantiated - in a direct way, and in a dynamic way, by using all above mentioned functions.


amirite the header file should be something like this?
what's wrong there, what's right, and what's still missing?

#ifndef CIRCLE_H
#define CIRCLE_H

class Circle
{
Circle();
void setCircle (int x, int y, int r);
int getCircle (int x, int y, int r);
void print (int x, int y, int r);
~Circle;
};
#endif
>>
>>51416424
nope, it doesn't.

this does
({}) ---<=8
>>
File: 1444353535620.jpg (8 KB, 250x227) Image search: [Google]
1444353535620.jpg
8 KB, 250x227
>>51416691
What does this do then, smart guy.
({}) ~~~c==3
>>
Beginner here. So, I'd like to write more concise code and right now it feels more like gloop. Any suggestions?

http://pastebin.com/wVPEdpjf
>>
>>51416684
go read a tutorial dumbass, and learn how to read errors.
>>
>>51416644
>Yes it does.
http://ideone.com/EmsliZ

>Nothing unsafe about them, they are as type safe as C can be.
that's wrong, C's macros are untyped while inline procedures are. that's why you should always favor an inline procedure over a macro.

>>51416644
>C doesn't have the abstraction capabilities to introduce new types other than through structs and passing those around.
that's why there GNU C.
>>
>>51416262
please stop breathing
>>
File: 84oC7QJ.gif (2 MB, 320x240) Image search: [Google]
84oC7QJ.gif
2 MB, 320x240
>>51412882
>What are you working on /g/?
I don't know.
>>
>>51416562

>it's licensed under GPLv3 and i have released the code 3-4 days ago.
Last I heard, you said it was proprietary.

>kvec.h example doesn't compile
Hmm... seems you're right. The author must be using a C++ compiler to build C code. Nonetheless, I found someone suggest a solution in the issues section and took the liberty of sending in a pull request (since they had not made one).

Like I said, small and hackable.

>unsafe macro (type safety literally threw into the trash)
>can't use kvec as first class value.
This is C we are talking about. Not C++, C.

>>51416651

In C: No.
In C++: Only if you overload the [] operator to do something silly.
>>
>>51416895
>http://ideone.com/EmsliZ
Don't use kv_a for setting values.
>that's wrong, C's macros are untyped while inline procedures are.
Macros are not 'untyped', what the fuck dopes that even mean?
Macros will substitute expressions with other expressions and the final result will go through the same compiler and type checker as anything else.
>that's why you should always favor an inline procedure over a macro.
Equivalent macro and inline function will have the exact same level of type safety.
>that's why there GNU C.
GNU C does not offer anything extra in regards to creating more 'first class values'.
>>
>>51416746
how did you fuck up a 3 round rock paper scissors match to be complex like shit. You have very explicit instances of code that aren't even properly commented. Every single variable name you wrote is shit and you cant tell what the variable is even supposed to be and some are even redundant because of the scope. You are using strings and chars like it makes it easier to read the code but it does the exact opposite because nobody does that, what you should use are ints, and bools (that are named well enough that you should know what the variable should be or atleast comment it in), and use a global enum and array of strings to spell it out, and to shorten the "string_eval" (holy fucking shit man did you really fucking name it string_eval and predeclared it 1 line before declaring it, I should've stopped reading right there why am i even writing this), and instead you could create a 2 dimensional int array that takes in the two enum values of rock/paper/scissors and returns -1 for draw, 0 for player wins, and 1 for comp wins (I don't fully recommend that, but when starting out in programming you really have to focus on making the code as short as possible because its the most important aspect of readable code but don't make heavily compact k&r code, but if your code is bracket heavy you might consider mixing k&r with it).

all your code is shit and hard to follow, my review is heavily biased towards my style of code and you should really google up other rock paper scissors examples and make sure you feel like shit.
>>
>>51417215
It's actually hilarious that he compares strings instead of just simple int or booleans. It's sort of cute, even if it's bad code.
>>
>>51417293
>compares strings
seems normal for a complete beginner. cute af
>>
>>51417041
>Don't use kv_a for setting values.
just copy pasted klib own example.

>>51417041
>Macros are not 'untyped', what the fuck dopes that even mean?
c's macro have no concept of types contrary to, for example, c++ templates.

>Equivalent macro and inline function will have the exact same level of type safety.
write the type safe macro of this.
void addVector2(vector2i *v, int b)
{
v->x += b;
v->y += b;
}
>>
>>51417305
>c's macro have no concept of types contrary to, for example, c++ templates.
Macros are not evaluated on the same level either, so it's a meaningless comparison.
>write the type safe macro of this.
#define addv2(v, b) ((v)->x += (b), (v)->y += (b))
struct v2 { float x, y;};
struct v2 v = { 1, 2 };
addv2(&v, "foo"); // compiler error


Type safety is not the issue with macros.
The potential problems with macros are that 'arguments' can be evaluated (or to be more precise: side effects) multiple times, and they invade global namespaces.
>>
>>51417215
k, so

>no properly commented code
I'll comment more
>Every single variable name you wrote is shit
can you give some examples of better names in this context? I'll see if I can find better rock paper scissors code variable names online
>You are using strings and chars like it makes it easier to read the code but it does the exact opposite because nobody does that, what you should use are ints, and bools
sounds more like a preference kinda thing but I'll look up more opinions to know for sure
>global enum
more googling for me
>string_eval
I realize that it's vague. I'll rename.
>holy fucking shit man did you really fucking name it string_eval and predeclared it 1 line before declaring it
for some reason I thought the function only worked like that before but I was wrong on that cuz it works now
> and instead you could create a 2 dimensional int array that takes in the two enum values of rock/paper/scissors and returns -1 for draw, 0 for player wins, and 1 for comp wins
I'll look at that.
>when starting out in programming you really have to focus on making the code as short as possible because its the most important aspect of readable code
I like this
>all your code is shit and hard to follow
thanks bby

Thanks for the suggestions. Really helps clear up the fog. I'll get better.
>>
>>51417391
>Type safety is not the issue with macros.
struct v3 { float x, y, z;};

addv2(&v3, 3);


yes, totally not a issue.
>>
>>51417418
That works with templates and any language which uses duck typing too.
And it's not an issue, it's often a very desirable property because you can re-use code for the common grounds of derived types.
>>
>>51417448
Yeah, if you just say that lack of type safety is not an issue one more time it'll actually stop being an issue so go ahead, it's in your hands to make macros safer!
>>
>>51417460
There's nothing type unsafe about that code.
>>
>>51417418
I assume addv2 takes a struct v2 * as an argument.
Yeah, that will throw a warning in C as it is. C doesn't just arbitrarily cast pointers to each other, with the exception of void pointers. You can cast the pointer and it should work and be defined behaviour if the initial struct members match up.
>>
Would this be an okay way to print a status message based on the values of some integer variables? In this case, an integer value of 0 is equivalent to Boolean 'false' and any other non-zero value is equivalent to Boolean 'true'. In pseudocode:

function Print_statusbits(int a, int b, int c) {
int status = 0;
string msg = "---";
int t_a = (a <> 0);
int t_b = (b <> 0);
int t_c = (c <> 0);

status = 1*t_a + 2*t_b + 4*t_c;

select case (status) {
case 0:
msg = "Normal operation";

case 1:
msg = "Overspeed";

case 2:
msg = "Overheat";

// and so on...
}
print (msg);
}
>>
>>51417510
>>51417448
>And it's not an issue, it's often a very desirable property because you can re-use code for the common grounds of derived types.
>mistype 2 instead of 3
>code still compile fine
>no error during runtime
>not an issue

have you ever read MISRA-C ?

"A function should be used in preference to a function-like macro. While macros can provide a speed advantage over functions, functions provide a safer and more robust mechanism. This is particularly true with respect to the type checking of parameters, and the problem of function-like macros potentially evaluating parameters multiple times."

People died because of these kind of errors (Toyota). Saying that macros are as safe as function is insane, one must be totally retarded or have not clue about c programming to say such things.
>>
>>51417527
sounds dumb to implement this yourself, haven't you heard of bitflags?
that seems to be what you're doing
>>
>>51417510

addv2 is a macro, not a function. There is no typing, It literally just substitutes the macro arguments in and pastes the code in. This is done BEFORE the compile step. as it is part of pre-processing. The result is this:

((&v3)->x += (3), (&v3)->y += (3))
>>
>>51417535
>mistype 2 instead of 3
>code still compile fine
>no error during runtime
>not an issue
It's supposed to compile because the only constraint was having an x, y field and that they can be added to.
Making things more general doesn't mean you lose type safety, it's a deliberate choice of wanting anything which satisfy that interface to be able to be passed to the function (or macro).
>People died because of these kind of errors (Toyota).
[citation needed]
>>
>>51417527
Why not just:
void print_status_msgs(status_t s)
{
string[] msgs = [ "Normal", "Overspeed", "Overheat", ... ];
for (i = 0; i < msgs.length; ++i)
if (s & (1 << i))
writeln(msgs[i]);
}
>>
>>51417535
I didn't follow the reply chain the whole way back. I think function-like macros typically aren't the right thing to use most of the time as well: inline functions are much better and the compiler will do a lot better job at optimising than you will.
Function like macros are still useful though. If you need to stringify or token paste the arguments, you have no choice. It can also be useful for wrapping functions and adding arguments.
void _fn(int arg1, ...);    /* expects pointers, terminated by NULL */
#define fn(...) _fn(__VA_ARGS__, NULL) /* User doesn't have to worry about terminating arguments */
>>
>>51417615
>I cannot use arrays inside functions
What the hell kind of shitty language is that? Anyway, it doesn't even need to be in the function. It can be any static or global array.
>>
File: bitop.png (15 KB, 837x530) Image search: [Google]
bitop.png
15 KB, 837x530
>>51417556
Seems like the programming language that I am using has these bit operations (in addition to the usual AND, OR, NOT). Would it be better/more convenient to implement this with these operations?

>>51417594
Unfortunately I cannot use arrays inside functions or bit shifts in this programming language.
>>
>>51417579
https://en.wikipedia.org/wiki/2009%E2%80%9311_Toyota_vehicle_recalls
http://usatoday30.usatoday.com/money/autos/2010-02-17-toyota17_ST_N.htm
http://www.safetyresearch.net/blog/articles/toyota-unintended-acceleration-and-big-bowl-%E2%80%9Cspaghetti%E2%80%9D-code
>>
>>51417630
The investigations concluded with mechanical failures.
And none of your sources pin point any errors specifically on C macro usage.
>>
>>51417626
>Unfortunately I cannot use arrays inside functions or bit shifts in this programming language.
Why would you deliberately use a programming language this bad?
>>
>>51417626
that lang is gay as hell
>>
>>51417630
>picture
How does one even write code this fucking bad?
>>
File: 65258007.jpg (82 KB, 461x403) Image search: [Google]
65258007.jpg
82 KB, 461x403
>>51417733
>>
I could download all images from 4chan threads with one line in a shell but I decided to do it "properly".

#!/usr/bin/env python3

import argparse, bs4, os, urllib.request

parser = argparse.ArgumentParser()
parser.add_argument("url", help="Link to 4chan thread")
args = parser.parse_args()

soup = bs4.BeautifulSoup(urllib.request.urlopen(args.url))

for link in soup.find_all("a", class_="fileThumb"):
image = "https:" + link.get("href")
filename = image.rsplit("/", 1)[1]
if not os.path.exists(filename):
urllib.request.urlretrieve(image, filename)
>>
>>51417697
I do not want to, but I have to use it because there are only two languages available for this task: Cicode and CitectVBA.
>>
>>51417970
why are so many people oblivious of the JSON API?
https://github.com/4chan/4chan-API
>>
>>51418020
and to the py request lib
>>
>>51414201
Look cool
>>
>>51414820
I'd think it's probably going to be passed as a parameter to a thread but needs to be retained for modification by the main thread making it difficult to use the stack for it.
>>
>>51418020


begin
api = JSON.parse(response.body)
rescue JSON::ParserError
fail "Invalid server response - probably invalid URL"
end

api['posts'].each do |post|
puts ">>#{post['no']}" if Prime.prime?(post['no'])
end

puts "Nice primes"
>>
>>51418288

-define(URL, "https://a.4cdn.org/g/thread/").
-spec threadcheck() -> ok.
threadcheck() ->
{ok, "200", _Headers, Body} =
ibrowse:send_req(?URL ++ "51412882.json", [], get),
BinBody = list_to_binary(Body),
{Start, Len} = binary:match(BinBody, <<"bumplimit">>),
Bump = binary:part(BinBody, Start + Len + 2, 1),
case Bump of
<<"0">> ->
timer:sleep(1000),
threadcheck();
<<"1">> ->
io:fwrite("/dpt/ is awaiting a new trap thread~n"),
ok
end.

>>
>>51418288
>>51418306
what language is that?
>>
>>51418317

>>51418288
Ruby

>>51418306
Erlang
>>
>>51418323
thx
>>
>>51417630
>2659 uses of directive #undef
what the actual flying fuck
>>
>>51418323
>Erlang

>has no JSON in the standard library
>has a fucking ASN.1 compiler and interpreter in the standard library
>>
File: sussman shig.jpg (71 KB, 500x375) Image search: [Google]
sussman shig.jpg
71 KB, 500x375
>>51414583
>unnatural
>implying infix operators are natural
>implying polish notation isn't more consistent with function application

>hating on s-expressions which help lisp process programs as data
>>
>>51418393
>has no JSON in the standard library
to be fair, JSON has only become very popular in the last decade or so. It's a small feature to add into a language, too.

For example, take C#, with its humongous standard library. (HUMONGOUS.)
even Microsoft's official ASP.NET servers use a third-party library to encode/decode JSON.
>>
>>51414949
>how long did it take for you guys to feel like you could program whatever popped in your head?
Half a month while reading SICP

>>51415275
>};
>that indentation
absolutely disgusting
>>
want to learn c and mb advance c, for embedded systems, any good cook book name please?
>>
>>51418491
honestly, you won't find a better book than The Commonsense Cookery Book.
I fucking love their Anzac biscuit recipe, man oh man.
>>
File: 1358242122207.gif (484 KB, 360x288) Image search: [Google]
1358242122207.gif
484 KB, 360x288
>>51418528
>>51418491
>>
>>51418528
ty man, you are awesome !
>>
File: IMG_20151119_125936.jpg (801 KB, 1632x1224) Image search: [Google]
IMG_20151119_125936.jpg
801 KB, 1632x1224
>>51412882
I've built some simple shit with an arduino where I can enter logic functions and it says what output it got on different logic inputs. accepts up to 4 inputs.
Maybe Imma build a simple desktop application to enter the functions even easier. Currently I gotta enter them into the source code
>>
http://pastebin.com/RfjcZSTJ

How would you do something like this through composition?

It's a data loader for a game, that loads all the data into memory in the background, but while it's loading it lets you ask for certain data, and that data gets priority to load first.

When it finishes loading all the data, it changes the class that holds the data into a simple dictionary which is based on enums, which essentially makes it just an array that gives you direct access, eliminating all the checks that were necessary beforehand.
>>
>>51418564
Was meant to reply to >>51415402
>>
>>51418559
Nice bomb, Achmed.
>>
File: 1447781526767.gif (2 MB, 370x335) Image search: [Google]
1447781526767.gif
2 MB, 370x335
>>51417970
WTF is wrong with you dude? You're seriously scraping 4chan pages??? The 4chan api was released like fucking 3 years ago, every board, and every thread in json format
>>
File: 1438100474004.jpg (28 KB, 726x677) Image search: [Google]
1438100474004.jpg
28 KB, 726x677
>>51417970
what is an api for 200
>>
File: 2190416-peter_molyneux.jpg (74 KB, 463x372) Image search: [Google]
2190416-peter_molyneux.jpg
74 KB, 463x372
I'm usually a sepples man but I'm willing to learn webdev(because no webassembly) to do the following: interactive infographic framework/editor thing with easy localization(think of xkcd's rocket or the rendering equation explained in 100 words being easier to popularize)

Am I being silly, is there something like this out there already, or should I start learning me some java scripts?
>>
>>51418442
The indentation in the output only exists because I didn't bother to do a full structured write-out. The }; will be fixed later to simply allow } instead. Likewise, the { #t } will be fixed to allow simply #t.
>>
>>51418559
nice what are those wires they dont look like standard dupont wires :)
>>
>>51415713
>Shall not be infringed IS common sense gun legislation.

Amen.
>>
>>51415649
>I don't know C
>>
>>51419260
>>I don't know C

This meme was never funny.
>>
>>51419014
just simple jumper wires. nothing special
>>
>>51419260
>I have never worked on anything more complex than fizzbuzz
>>
File: 1407096950033.jpg (45 KB, 612x612) Image search: [Google]
1407096950033.jpg
45 KB, 612x612
Is there a faster way to walk through binary tree than basic recursion like:
void 
find(Node* node)
//check and return
find(node->l);
find(noed->r);

I'm storing in nodes parents for other purpose. Maybe I could use it somehow?
I just need to store some end leafs of the tree in the list.
>>
>>51419553
If the tree is balanced, you can store it in an array and iterate it as needed.
https://en.wikipedia.org/wiki/Binary_tree#Arrays
>>
>>51419553
No, that's the only way. If you regularly need to access specially the end leaves then you could modify your insertion algorithm to store end leaves in an additional list.
But unless you are sure to potentially save thousands of entries in your tree it's not worth the trouble.
>>
    public void mix(){//mix the cards
int temp;
temp=card[0];
card[0]=card[1];
card[1]=temp;


Could someone help me mix 52 cards(full card deck) with a random card in java by using (int)(Math.random()....?
I can't figure it out .
>>
>>51419605
unfortunately it's not
>>51419627
I see thanks.
>>
>>51419642
>Could someone help me mix
http://stackoverflow.com/questions/1519736/random-shuffling-of-an-array
>>
>>51419642
> mix 52 cards(full card deck) with a random card
What does this mean? Insert a single card into random position or shuffle the whole deck?
>>
>>51419475
>I don't know C and I need to proceed with extended damage control
>>
>>51419687
shuffle the whole deck.
>>
>>51419706
>extended damage control

People who use extensions are heathens.
>>
>>51419719
See >>51419682 then.
>>
>>51419706
>I have been thoroughly BTFO and my anus aches
>>
>>51419687
No you're supposed to loop through all the cards and change the place of every card with a random card.
>>
>>51419642
ArrayList<Card> cardList = new ArrayList<>();

for (Card card : cards) {
cardList.add(card);
}

Collections.shuffle(cardList);
>>
>>51419751
Because our brains need to react fast and save energy, people know they're right, but forgot why they are.
>>
When programming a calculator, how would one handle parens, without using recursion? As in, the inner-most parens are evaluated first.
>>
>>51419818
Using a stack of course, where the innermost expression is at the top of the stack.
>>
>>51419818
stack or counter.
>>
>>51419855
>>51419857
I see.
My thought was to just loop through the characters until I found the first ), go back until I find the ( and just replace.
>>
>>51419785
>I don't know what I'm talking about but I'll just sprinkle some memes
>>
>>51419894
>it hurts so much please make it stop
>>
>>51419879
why can't you use recursion?
pic related is what I used in some parser I made 6 months ago
basically I loop through all of my tokens, isolate a group, then parse its tokens (which then can parse groups inside of it, recursively).
>>
Hey /g/, I see a lot of C fans around and I was wondering if someone can tell me if this snippet is correct.
void float_as_u(float f, unsigned *u)
{
if (sizeof f != sizeof *u) {
abort();
}
memcpy(u, &f, sizeof *u);
}

int test(void)
{
float f = 1;
unsigned u, *p = malloc(sizeof *p);
if (!p) {
abort();
}
float_as_u(f, &u);
float_as_u(f, p);
printf("u = %u\n", u);
printf("*p = %u\n", *p);
free(p);
}
>>
>>51419957
>muh indeterminate lifetime
>muh lack of knowledge
>>
>>51416517
>https://github.com/attractivechaos/klib
>uses GCC-only features
>uses pthreads
>from hash table ("The capacity is a power of 2.")

1. It's unportable as shit.
2. It's even more unportable because it uses shitty pthreads (we have C11 threads now)
3. Hash tables are fastest if they have a capacity matching a prime number.

Basically your shitty toolkit is shit and no one wants to touch it. Fuck it fuck it.
>>
>>51419987
>guaranteed silence from the "C experts" of /dpt/
>>
>>51419976
where is pic
>>
>>51420054

Of all those, kvec.h probably gets the most usage, and it's pretty slim.

Don't hate it.
>>
>>51420054
>we have C11 threads now
where?
>>
>>51419987
probably
>>
>>51420063
>>51419987
Tell me your intent, and I'll tell you if your snippet of code makes sense. Alone, a snipped of code may be correct and executable without making any sense.

As is, I don't see any fault but you won't go very far with this, your program will abort on many cases. Ideally, you'd want your program to work on as many machines as possible. Treat the special cases as manageable cases.
>>
>>51419808
Mate you're supposed to use mathrandom and shuffle every card with a randomly selected other card.
>>
>>51419996
>muh fizzbuzz is the only program
>muh lack of knowledge
>>
>>51420096
http://en.cppreference.com/w/c/thread
>>
>>51420054
>1. It's unportable as shit.
Nope.
>2. It's even more unportable because it uses shitty pthreads (we have C11 threads now)
pthreads is more portable than C11 threads.
>3. Hash tables are fastest if they have a capacity matching a prime number.
With quadratic probing you can guarantee that you always fill up every empty slot when using a power of 2 size and triangular number sequence.
>>
>>51420155
that's a reference; where's the implementation? it was claimed to be more portable than pthreads, so I'm asking for implementations of it.
>>
>>51420151
>I'll keep memeing
>stuff like >>51419987 is over my head
thanks for making my point for me
>>
How are you supposed to traverse through a binary search tree. Most solutions Ive seen involve que's which make the tree seem usless to me. Say we wanted preorder traversal. When I hit the last element on the left side of the tree, how do I tell it to go to the first element on the right
>>
>>51420163
>>1. It's unportable as shit.
>Nope.
It does have some shitty unreliable code though: from just browsing kvec.h I see no error checking and thus memory leaks and undefined behavior galore.
>>
>>51419879
Use a stack. See the shunting-yard algo.
>>
File: grandmajpg.jpg (719 KB, 1818x1228) Image search: [Google]
grandmajpg.jpg
719 KB, 1818x1228
>>51420265
>I see no error checking

This is C, after all.
>>
>>51420200
The two main ways to visit the nodes of a binary tree are breadth-first and depth-first. Breadth-first search involves queues because you look for all nodes of a level before going forward. Depth-first search is stack-based, it goes to leaves first before going back.
Order of visit only matters for deciding when any operation concerning the current node may occur (before, in the middle or after visiting successors). Whether you want to visit the left or right subtree first is a matter of taste.
>>
>>51420265
What, no error checkin in a header file?
Who would have thought.
>>
>>51420265
Container library code should not do error checking, that's up to the user.
>>
>>51420054
>unportable because it uses shitty pthreads (we have C11 threads now)
C11 threads are optional, you dumb fuck, almost nobody implemented them yet. How the fuck would that be more portable?
>>
>>51420310
aka shit code
>>
>>51419987
Depends on what you meany by 'correct'.
It will compile but is highly implementation specific and potentially undefined behavior.
>>
>>51420311
Please go post in a desktop thread if you have no idea what you're talking about.
>>
>>51420341
Well, if it contains undefined behavior then it can't possibly qualify as 'correct', can it? If compiling was all it took to be considered correct, that's easily verifiable without posting on /g/.
>>
>>51420346
You should leave the programming to people who actually know what they're doing.
>>
File: oh you.png (511 KB, 836x964) Image search: [Google]
oh you.png
511 KB, 836x964
>>51415799

easy
You help kill those sandniggers
>>
>>51420385
But I know what I'm doing. You obviously don't, if you think error checking is unnecessary.
>>
>>51420398
>But I know what I'm doing.
No, you don't.
> if you think error checking is unnecessary.
That's not what I said, maybe you should learn basic English first as well.
Thread replies: 255
Thread images: 32

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.