[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: 36
File: trap programmer.png (1 MB, 1702x2471) Image search: [Google]
trap programmer.png
1 MB, 1702x2471
Old thread at >>51613348

What are you working on, /g/?
>>
First for cats
>>
>>51617317
Fuck you the captcha failed me retroactively
>>
Well,if anyone here knows JUnit whats the point of Test Runners?My test run fine without it.
>>
Say I have a library, Foo, and I want to make it so any methods called, such as Foo.FizzBuzz, ends up instead calling a different library, Bar, and its method Bar.BuzzFizz. How would I go about doing this sort of binding in C#? I'm trying to transition code from one DLL to another without making the users have to change their code
>>
File: ruff victory.jpg (58 KB, 620x465) Image search: [Google]
ruff victory.jpg
58 KB, 620x465
Welcome to the /Dog Petting Thread/! Enjoy your stay!
>>
So our latest assignment for school includes setting a password on an FTP client we make in Python.
What's the difference between active and passive FTP? I vaguely recall something about the port being different?
>>
who /failure/ here
>>
>>51617427
Just get rid of your cats and you'll be fine.
>>
who /assembly/ here
>>
>>51617474
fuck off dogposter
>>
>>51617556
i've only used it to implement frob
>>
help .
>>51617597
>>
>>51617565
You're in the wrong thread, friend.
This is /daily petting thread/ not /please bandage my hand because this little shit attacked me thread/
>>
>>51617579
Would you know anything about this? >>51616895
>>
>>51617632
converting to hex is like converting to binary
and if you're having trouble, just convert the number to binary and then just group every 4 bits (right to left). then you can just look the hex version from a table
>>
>>51617650
Its weird, the output is in Hex but I feel as if arithmetic is being performed in Decimal.
>>
>>51617650
e.g.
normal method:
50 = 0(256) + 3(16) + 2(1)
-> 32
vs
50 = 1(32) + 1(16) + 0(8) + 0(4) + 1(2) + 0(1)
-> (00)11 0010
11 -> 3
10 -> 2
32
>>
>>51617677
Thanks, the second method doesn't really make sense to me right away but I definitely understand how to use the formula.
>>
>>51617731
The second method is this:
Convert it to binary.
Group it into sets of 4 bits, from the right to the left.
(E.g. 101011111 > (000)1 0101 1111

Every 4 bits of binary is directly translatable to a hex digit. Hex digits go 0-9, A-F
(000)1 (binary) -> 1 (decimal) -> 1 (hex)
0101 (binary) -> 5 (decimal) -> 5 (hex)
1111 (binary) -> 15 (decimal) -> F (hex)

You can just have a table like this:
binary -> hex
0000 -> 0
0001 -> 1
0010 -> 2
...
1010 -> A (A is 10)
...
1111 -> F (A is 15)

And then, _after grouping the digits right to left_, swap each group with the one in the table

(you can do that backwards too)
>>
>>51617665
Arithmetic isn't performed in any specific base. Binary, decimal, hex, those are all just representations for storage in memory or printing to the screen.
>>
hey, you fucking perverted faggot, can you fucking stop making these threads?
do you want more thread wars? because we can give you that and more
>>
>>51617930
I think what he means is that the operands are in different bases, but it's treating them as if they're in the same base
>>
>>51617932
XdD THRED w4r 4chan culture!!!!11!1111
>>
>>51617944
It has nothing to do with the arithmetic, it's how the literals are being interpreted.
>>
>>51617944
>>51617930
I'm having problems with my Branches and ANDs because arithmetic isn't working (the character '1' shows up as 31 in my accumulator but when I subtract 30 from the accumulator, I'm getting a negative number)
>>
>>51618058
That's literally what I said.

>>51618085
What negative number?
>>
>>51618085
Mate. That's the ASCII code for the character "1".

In any case, it's reading the literals as hex so you need to find the hex representation of decimal 30.
>>
>>51618118
I only kind of remember it. The number was either FFFFFFFA or FFFFFFF8

>>51618119
I knew that was the ASCII for 1 but I was assuming the program handled inputs and declared variables in Hex so I declared it as I 30 (Integer 30)
>>
File: 01e.jpg (33 KB, 576x640) Image search: [Google]
01e.jpg
33 KB, 576x640
Could someone explain me how the hell do you do the modulus 2 division for CRC?
>>
I'm trying to understand linked lists. I found a tutorial online and it yielded this
struct node{
int data;
struct node* next;
};

struct node* BuildOneTwoThree(){
struct node* head = NULL;
struct node* second = NULL;
struct node* third = NULL;

head = malloc(sizeof(struct node));
second = malloc(sizeof(struct node));
third malloc(sizeof(struct node));

head->data = 1;
head->next = second;

second->data = 2;
second->next = third;

third->data = 3;
third->next = NULL;

return head;
}


I think I understand the concept of them, but what would you use them for?

They seem a little to manual, which is not a problem but it makes me feel like there is a more robust way to do it
>>
>>51618416
>They seem a little to manual
Welcome to C.
>>
>>51617607
if you can't do that without the help of others, you're not right for the job. This is a very basic thing you google.
>>
File: slist-ir-2.png (5 KB, 386x180) Image search: [Google]
slist-ir-2.png
5 KB, 386x180
>>51618416
it's a basic structure. Each node of the list holds a value and a pointer to the next element.
>but what would you use them for?
when you want to quickly add or remove elements from the front or back, and you don't need random access to its elements
>They seem a little to manual, which is not a problem but it makes me feel like there is a more robust way to do it
use a higher level language, something that isn't C.
C is good to understand how they work tho
>>
>>51618492
Yeah like I said I'm not worried about it being to manual it's just that I fucked my education by learning a higher level first
>>
>>51618588
My college also only taught me higher level languages. I still had to make and understand different data structures and build them myself in Java.
>>
>>51618588
it has its pros and cons. In higher level languages you can focus on concepts. In lower level languages you have to learn the concepts plus all the technical details of how a computer works, which in my opinion slows down your learning, because you should first learn how to program, and when you grasp the concepts move to learning about the computers.
And also I forgot in my previous post.
You should create an interface for managing the list. You are manipulating the struct's fields directly, when you should create functions that abstract that. You should have a function to create a list, adding a node, removing a node, etc
>>
hello senpai, need a good c book for embedded programming
>>
I'm brand new to programming and decided to devote 12 hours a day into learning. 8 of the 12 hours are paid and the other four are at home unpaid.

Currently I am using mooc, head first Java, and in house training. I've been doing this for about a week and I'm on week six of mooc, but I've been considering doing freecodecamp or the Odin project while not doing Java. Would I be stretching too thin?

What are some good resources after completing the mooc assignments?
And last question, am I pretty fucked without a cs degree as far as learning more complex cs theories and algorithms? Or is that something I could learn?
>>
>>51618900
>its /b/
Sounds about right.
Enjoy your stay.
>>>51618888
>>
File: 1387191689578.jpg (34 KB, 402x500) Image search: [Google]
1387191689578.jpg
34 KB, 402x500
>>51618416
Linked lists are very useful for things where you need to keep track of them, but you don't know exactly how much you'll need to track.

For example, let's say you wanted a program that would go through each word in a text file and add each unique word to an array. So, if you had a text file with something like "the fish the cat the dog" in it, you would have an array with ["the", "fish", "cat", "dog"].
Well, something like this could work for such a small file:

char *words[20];

But what are you going to do when you start reading through larger text files? If you have 100 unique words, that's clearly not going to fit into the array. Do you initially make the array bigger then? How much do you need to account for? Are you going to limit your user on what kind of files they can open? Are you going to make the array size equal to the number of words in a dictionary?

If you tried to account for a possibly large amount of words you need to store, then you just end up wasting a lot of space, since it will probably never be fully used.

This is where linked lists come into play. For every unique word, make a new node and store it in there. Works pretty much like an array, but you have space for exactly how much you need; no more, no less (unless you run out of memory, but that's a different story).

The core things you need for linked lists are: a structure that has a pointer to its own type, a head pointer that points to the first thing on the list, and a current pointer that points to the last thing on the list (the current pointer isn't even technically needed, but makes things much easier when adding new nodes). Furthermore, you're not even limited to that specific structure. You could make nodes that have 15 variables inside of them to store all sorts of things.

Hope this helps senpai.
>>
Why
>>
>>51618995

Some closet faggot that's asshurt about an OP picture
>>
Fucking Applefags derailing a proper thread with their propaganda again.
>>
dpt reaches new peaks in quality
>>
>>51619153
Absolutely leld
>>
What's the best way to implement a month-year data type in C++ (given, for example, Jan 2011) so I can sort them and do math on them? I thought about vector<vector<int> > but that seems wasteful.
>>
>>51619256
It's amazing what modern technology can do in terms of surgery

Shame it'll never solve the jaw, hands, shoulders or body in general
>>
>>51619270
nanoseconds and convert it on demand
>>
>>51619270
include ctime
store as time_t
retrieve as tm (localtime)
>>
Hi, is this the dog petting thread?
>>
>>51618416
Write more functions.

http://pastie.org/private/qlkbdxrgpycruluqlsveea
>>
>>51618979
>>51618655
So would an interface for this look something like this?
struct node{
int data;
struct node* next;
};

struct node* build_list(int data){
struct node* ret;
ret = malloc(sizeof(struct node));
ret->data = data;
return ret;
}

struct node* add_item(struct node* list, int data){
struct node* item;
item = malloc(sizeof(struct node));
list->next = item;
}


I'm not sure how I would approach removing a node
>>
>>51619390
forgot the
item->data;
in the last method
>>
>>51619390
you remove a node by making the 'next' in the node before the one you want to remove the address of the node after the one you want to remove. That way it's not linked anymore
>>
>>51619390
Removing a node is relatively simple, but it depends on what kind of list you have. If you have a vanilla linked list, you delete an item by deallocing its memory and making the pointer to that node either point to the next one, or if it was the last one point it to NULL.

Also your add_item is flawed, because it assumes you're getting the last item in list. It'd be better to add it to the end of the list automatically, which is done by going over every node until you're reached one where next points to NULL.
>>
dude weed lmao
>>
I'm looking for a way to achieve a ruff victory, can anyone else?
>>
>>51619513
Can anyone help*?
>>
>>51619513
for more danke memes please visit reddit
>>
>>51618900
>its /b/
did you even see the pic in the OP?
I'm glad did random guy did that. too bad no one recognizes that the OP is the SAME OFF-TOPIC SHIT
>>
°FROB°
>>
File: sticker,375x360.png (60 KB, 375x360) Image search: [Google]
sticker,375x360.png
60 KB, 375x360
>>51619506
BEST POST IN THIS THREAD
>>
>>51619548
"\"FROB\""
>>
File: whosagoodboy.webm (3 MB, 720x405) Image search: [Google]
whosagoodboy.webm
3 MB, 720x405
>>51619534
No, thank you.
They probably don't have a /dog petting thread/.

webm related, GTP if he were a dog.
>>
File: desu~.png (255 KB, 957x911) Image search: [Google]
desu~.png
255 KB, 957x911
I made this: https://www.mediafire.com/?37i5331ha9uxxn7

TV series watcher.
I have a scrape bot that gets links from all over and puts them on my host, and this is the client which updates the links from there.

Rips the files from the videohost and runs in default browser with html5 embed.

I also put a single ad on top, but it's less than a second between choosing the episode and watching it so it's already a big hit with my normie friends.
>>
In your build_list, be sure to do this before returning:

ret->next = NULL;

Not only is this helpful in being safe (this way, you won't accidentally try to look inside a next pointer when it's at the end of the list), but it's useful in loops too. The typical way you would go through a list in a loop would be something like:

currentNode = headNode;                                    //have a pointer point to the first node

while (currentNode != NULL) { //keep going until currentNode points to nothing

printf("data for this node is: %d\n", currentNode->data); //print the node value

currentNode = currentNode->next; //set currentNode to the next node
}



As for removing a node, the most important thing to keep in mind is that you are ALLOCATING memory, which means you need to FREE it afterward.

After that, it's just doing some logic jumps. If you want to remove the end of the list, then get to the second-to-last node (you could do something like the loop above, where you check for currentNode->next != NULL instead, that way you'll stop on the second-to-last node and the while loop will break). Once you're there, just free the node, like:

free (currentNode->next);

And then set the now-last node's next to NULL:

currentNode->next = NULL;


I'll draw up a picture for removing a node from the middle and post it in a moment.
>>
>>51619573
haha holy shit, I'm crying
>>
>>51619573
that' one useless dog
>>
http://stackoverflow.com/questions/34005179/why-compilers-dont-throw-an-error-when-you-compare-literals

well /g/? why?
>>
>>51619621
because you touch yourself down there
>>
>>51619584
iaintclickingthatshitnigga.jpg
>>
>>51617301
well, this is how you know /dpt/ died: faggots, trannies, anime, cats and dogs
>>
>>51619621
because nobody is dumb enough to do that unintentionally
>>
>>51619584
.exe? Fuck off pal.
>>
>>51619649
apparently android devs are.

heres the link thats inside the question:

https://lkml.org/lkml/2015/11/19/454/
>>
>>51619645
It's raining cats and dogs in here! ha ha!
>>
>>51619644
>>51619679
damn, /g/ is afraid of technology, okay.
sandbox it, reverse engineer it, i don't care.

I was just kinda proud of it working so well
>>
>>51619573

You got me.
>>
File: 1382617855470.png (8 KB, 443x376) Image search: [Google]
1382617855470.png
8 KB, 443x376
getters and setters are deprecated. just use public.
>>
>>51619737
>sandbox it, reverse engineer it, i don't care.

Why not release the source code upfront?
>>
>>51619755
or a sane language wich setter and getter syntax is the same as using the public field.

ruby/c# allow this.
>>
>>51619763
When are we going to pair program and rewrite the Linux kernel in D?
>>
>>51619755
Yea! Let's throw encapsulation, one of the more important features of OOP, away!
I bet they just invented it to pester us
>>
>>51619621
Because a lot of that it takes work, it's slower, and it requires you to work around the compiler. Of course, there are certain kinds of logical errors that can be found at compile time quickly and efficiently without limiting the programmer. Look into dependently typed languages if you're interested in offsetting (some) logic into the type system to allow for ahead-of-time logic verification. Also, you might be interested in whole program verification if you want to see this kind of thing.
As an example, the question talks about infinite loops. Most dependently typed languages offer some totality checking, which can basically prove that a function will (eventually) return a value (i.e. will not continue executing for an infinite period of time).
>>
>>51619787

One of these days. Then Linus Poor-valds will be BTFO for good.

>>51619776

Properties are tight.
>>
>>51619795
every real programmer moved on to a data centred paradigm anyway. oop is literally for fags.
>>
>>51619843
>Properties are tight.

yeah, i like it when the distinction between a method and a attribute blurs.

C# makes this extremaly well, for a statically typed language...
>>
>>51619763
I made it kinda hoping I could make some money running that ad on top, and if you see it it kinda becomes obvious how I made it.

Maybe it's just me being a dick about it, but it's also probably the reason I didn't just make it in js in the first place.
>>
>>51617349
Write some sort of wrapper?
>>
File: 1448196823160.jpg (101 KB, 560x431) Image search: [Google]
1448196823160.jpg
101 KB, 560x431
Who /first semester of programming/ here? This is harder than I thought it would be. Where's a good place to by pantsu?
>>
>>51619878

Look, niggers can't be choosers. Complain about functionality elsewhere.
>>
File: 3000_hours_in_paint.gif.exe.png (95 KB, 1815x1636) Image search: [Google]
3000_hours_in_paint.gif.exe.png
95 KB, 1815x1636
>>51619390
>>51619595
Also be sure to make the next pointer point to NULL in the add_item function as well.
Here's a picture for removing a node in the middle of a list.
>>
File: 1425538677355.jpg (149 KB, 1080x720) Image search: [Google]
1425538677355.jpg
149 KB, 1080x720
>>51619899
Nobody cares about your proprietary shitware, this is the Daily Programming Thread not your personal phishing site, so post some code or fuck off you spammer cunt.
>>
>>51619953
i am not complaning, i mean that.

i really like that theres no distinction between attributes and methods.

real object oriented theory only talks about messages.
>>
>>51619976
>i am not complaning, i mean that.

Sometimes it is hard to tell when people are being serious or sarcastic on /g/. Especially when we're talking PL functionality.
>>
>>51619961
HotGrill.getAss().insert(myDick);
>>
>>51619835
I agree with this. I wish mods were listening.
>>
>>51619961

This 'woman' looks like a man.
>>
>>51619993
*** error: insert expects long long (got: short)
>>
>>51619961
If you don't care, don't look at it, simple as that.
I already told you what I made, why the fuck is everyone mad about it.

Don't touch it, okay, it's fine.
/dpt/ is as much mine as it's yours, shove another stallman doll up your ass and read literally anything else on the thread
>>
what the fuck? I thought multithreading would speed up stuff (in this case, my mandelbrot drawing), but it only slowed it down. What a fucking let down that shit is, even with 8 threads simultaneously....

I'm fucking rustled. Now i have to tweak my algorithm... ugh
>>
>>51618416
>a little too manual
Pretty much any data structure is "manual" behind the scenes. Which is why you abstract them into basic operations with functions.
>>
File: 1381702459715.gif (983 KB, 500x364) Image search: [Google]
1381702459715.gif
983 KB, 500x364
>>51620022
>>
>>51620039
what language?
>>
>>51620065
C#
>>
>>51620074
kek
>>
>>51620039
parallelism is often not useful
this talk gives a pretty good example of how sometimes parallelism will slow your program down: https://www.youtube.com/watch?v=cN_DpYBzKso
>>
>>51620074

Multithreading doesn't 'just work', you know.
>>
>>51619696
>android dev
>not some 2nd year Indian CS student
>>
File: Lena-and-Rosie-Pula.jpg (2 MB, 2000x1333) Image search: [Google]
Lena-and-Rosie-Pula.jpg
2 MB, 2000x1333
>>51620006
You're right, let me post women more to your liking.

>>51620033
Eat shit you fucking idiot. Nobody cares about what you made if you're not going to post the source you fucking Russian botnet faggot.
>>
>>51619941
check the ad on top or bottom of the board, they sell a couple of pantsu.
>>
>>51620093
Neither do niggers, yet you're still wasting time on them.
>>
File: IMG_20151130_173050302.jpg (2 MB, 2340x4160) Image search: [Google]
IMG_20151130_173050302.jpg
2 MB, 2340x4160
Goddamn, this shit's thick
>>
File: TAOCP-box.png (1 MB, 1000x742) Image search: [Google]
TAOCP-box.png
1 MB, 1000x742
>>51620125
bitch please
>>
>>51620125
It's gooooooooood. Sparked my love of graph algorithms
>>
>>51620039
you know there is overheard for multithreading?
>>
>>51620125
>>51620151
>he bought the book
C U C K E D
The only reason to buy books is if its the Holy Bible
>>
>>51620231
the second one is stolen from Google Images, christfag
>>
File: 1431725338012.jpg (20 KB, 225x270) Image search: [Google]
1431725338012.jpg
20 KB, 225x270
Where's the standard place to do error checking in C? I write my functions to only focus on one specific task and return a failure or success, and I want to keep my main() clean as well by doing error checking inside another function. However, if an error function requires quitting to desktop, I want to be able to free any memory I've allocated during runtime before exiting. Am I just stuck with doing error checks and exits inside of main? Maybe I could make a list of each thing I've allocated and pass it to error-checks, and on failure free them in there and exit, but this seems like a pretty retarded way to do things.
>>
>>51620207
I got it off Amazon, $10 off through this
http://www.amazon.com/b/ref=HBN15_SO30?ie=UTF8&node=8885530011&pf_rd_m=ATVPDKIKX0DER&pf_rd_s=special-offers-1&pf_rd_r=0EKHWGM4GY4FMB7J0F6H&pf_rd_t=201&pf_rd_p=2305973342&pf_rd_i=0262033844
The deal will be over by tomorrow though
>>51620231
Physical copies >>>>>>>>> Online books
>>
>>51620263
>The deal will be over by tomorrow though

I'll probably pick it up at my college bookstore. I get a big discount.
>>
>>51620285
college bookstores are the scum of the earth
>>
>>51620263
>Physical copies >>>>>>>>> Online books
Kek.
>hey anon,whats with those books on your shelf?Dont tell me you read that virgin stuff?
>Chad has only philosophy and business books ,anon.
>>
>>51620257
>I want to be able to free any memory I've allocated during runtime before exiting.

Literally why? Are you retarded, anon? If your program is terminating, DO NOT FUCKING WASTE TIME FREEING YOUR MEMORY.
>>
File: 1433891629140.webm (240 KB, 600x440) Image search: [Google]
1433891629140.webm
240 KB, 600x440
can i get some /dog petting thread/ in here
must achieve a ruff victory.

I'm going to crosspost a funny webm that's programming related. it has sound though, which is why I'm not posting here.
>>
>>51620310

They are, but at least I get cheaper books.
>>
>>51620335
https://i.4cdn.org/gif/1448927101394.webm
>>
File: 1421680731602.jpg (157 KB, 500x500) Image search: [Google]
1421680731602.jpg
157 KB, 500x500
>>51620327
>Chad [...] books

Yeah, I don't think so.
>>
>>51620328
That's what I thought at first, "why bother if OS frees it anyway", but apparently not all OS's do this, which is why I want to make sure I free everything I use before exiting. I want to make my program port-friendly in every sense.
>>
>>51620371
>but apparently not all OS's do this

Which operating systems don't reclaim memory once a process is dead?
>>
>>51620371
Pretty much any modern OS is gonna do that for all resources acquired through OS calls.
>>
>>51620371
What OSes is your program shipping on? Seriously.

Here's a great article on why methodically freeing your memory on a modern OS is a terrible idea: http://blogs.msdn.com/b/oldnewthing/archive/2012/01/05/10253268.aspx

The gist of it is, if your program takes more than maybe 200ms to terminate when the user tries to close it, you're pissing them off. If your program isn't doing something like flushing important data to disk, there is no excuse. If it takes longer than a second, I'm pkilling your shit anyway.
>>
>>51620405
git follows this philosophy too, and look where it ended up.
>>
>>51619456
So would add item look something like this? I am not in an enviorment where I can compile this
struct node* add_item(struct node* list, int data){
struct node* current;
current = list;

struct node* new;
new->data = data;
new->next = NULL;

while (1) {
if (current != null) {
current = current->next;
}else{
current->next = new;
}
}
}


Going to work on the delete now
>>
>>51620450
The most popular and successful VCS software in existence?
>>
Convince me to switch from Python 2.7 to 3.

Pro tip: you can't.
>>
>>51620460
ppppffffttt it'll never catch on
>>
>>51617301
another thread encouraging boys to be traps
>>
>>51620465
>convince me to switch from shitty meme language 2.7 to shitty meme language 3.0

No thanks.
>>
>>51620465
Have fun facing deprecation.
>>
>>51620465
they are both fine for different purposes.
>>
>>51620465
Good replybait. Here's the thing though, I'm gonna give you the gift of knawledge. A little "insider knawledge" up here in the Hollywood Hills, in my garage. People aren't switching from Python 2.7 to Python 3.X, they're switching from Python 2.7 to Golang. Just a short post, hope you like it, later.
>>
>>51620388
>>51620397
>>51620405

Here's the link that I found talking about it.

http://stackoverflow.com/questions/2213627/when-you-exit-a-c-application-is-the-malloc-ed-memory-automatically-freed

The general consensus is that most operating systems will free it automatically, but there are some old ones (someone mentions "old versions of NetWare", and I recall seeing DOS in there somewhere as well) that do not.

However, I do agree that if the OS can handle it, then we might as well let it do that, especially since it makes the program exit quicker and feel like it responds faster for the user. I was just trying to maintain 'good practices'.

I guess another thing to consider is how long ago did it become standard for an OS to automatically free memory for you; it's probably safe to assume that there won't be an issue with this. Still feels a bit sloppy though, but oh well.
>>
>>51620557
For how many years have you been programming?
>>
>>51620557
thats why you code in Java.
>>
>>51620585
[spoiler]About 4 years now[/spoiler]
>>
>>51620557
Oh yeah definitely once you go back in the years, you'll encounter a lot less modern OS amenities like you've noted. DOS variants in particular are absolute bare minimum OS.
>>
>>51620257
Read the manuals for on_exit (3) and atexit (3). Calling exit() calls the functions you specify; _exit() exits without calling them.
>>
>>51620557
Would you rather your program run better for 99.999% of your users, and then when one asshole is running an embedded copy of Windows 98 and needs your program to clean up after itself tell him to go fuck himself, or make your program a more miserable experience for everyone?

That stackoverflow answer pretty much proves that the average commenter's idea of "good practice" is just 100% circlejerk and not actually based off of real experience.
>>
>>51620465
Go home Google, you're drunk
>>
>>51620652
>on_exit
So I can set up memory to be freed in case an exit is called later on? Holy shit that's comfy as fuck.

>>51620658
Weird. My professors always tried to enforce memory management, even on exit. I would prefer a better user experience over unnecessary precautions though.

So then, back to standards of where errors should go: separate function call, keeping it out of main?
>>
>>51620455
Something like that but you're being a nigger.
Write it like this:

 
struct node *
newnode(void) {
struct node *n = malloc(sizeof(struct node));
n->data = NULL;
n->next = NULL;
}

struct node *
makenode(int data) {
struct node *n = newnode();
n->data = data;
return n;
}

struct node *
list_append(struct node *list, int data) {
for (struct node *cur = list; cur && cur->next; cur = cur->next)
;
cur->next = makenode(data);
return cur;
}

void
list_free(struct node *list) {
for (struct node *cur = list; cur; cur = next) {
struct node *next = cur->next;
free(cur);
}
}
>>
File: normiechan screencap.png (485 KB, 1920x1080) Image search: [Google]
normiechan screencap.png
485 KB, 1920x1080
Im currently working on a 4chan/9gag hybrid.
It will basicly be a website where we can redirect 9gag plebs and other memesite people.
It will contain all the edgy and dank 4chan memes in a nice 9gag, normie friendly format.

>pic related
a screecap of the prototype.
>>
>>51620832
>downvote isn't sage
Dropped
>>
>>51620658
I'd rather have my unit- and performance tests not hemorrhage memory because some retard thought memory management in C was optional.

If you rely on process exit to do your memory management, you're a retard and should use Java.

If you want to leave off the free_my_shit(..) for when your main binary exits that's fine, but that free_my_shit(..) function needs to exist and it needs to work.
>>
>>51620832
you sure love being part of a botnet and giving away all your privacy, don't you
lil' fag
>>
How hard is it to implement a graph data structure and graph search algorithms in C? We've only been learning C for about two weeks, do you think it's too early?
>>
>>51620841
Better ?
>>
>>51620897
I guess
>>
>>51620861
Totally dependent on how you have your memory management set up. Typically unless you're writing server software, you don't want your memory allocations to be unbounded. You have a target memory footprint. I generally allocate it at once, on startup, as a memory arena, and then dole it out to functions that need it. Guaranteed zero leaks.
>>
>>51620871
You can implement a graph with n vertices as a nxn 2D array. Searching the array is fairly easy.

More efficient implementations exist, but that should be good enough if you've only been learning for two weeks.
>>
>>51620897
>not 上げ and 下げ
Do you even UTF-8?
>>
>>51620811
>newnode supposedly returns node*
>doesn't actually return anything

wew laddie
>>
>>51620974
i have no clue what you are saying
>>
Just for fun I peaked into the source code of a FOSS'd game hack I downloaded a year or so ago.

10000+ lines of Visual Basic code spread across four source files.

How the fuck do people do this? Seriously how do you sit down and say I'm going to write ten thousands lines of code in VISUAL BASIC and then release that code for absolutely no incentive whatsover.

At least 50% of it was hugely copy/pasted with slight changes, too. It looked like it was relatively easy to maintain but fuck.
>>
>>51620995
And I don't really know why I'm returning cur from list_append. Shit happens when you don't compile things.
>>
>>51621010
>he posts on a mongolian basket-weaving forum and doesn't even know moonspeak
>>
>>51621019
>And I don't really know why I'm returning cur from list_append.

It's like how strncpy returns dest for some reason.
>>
>>51621025
still no clue
>>
>>51621010
Sage (下げ)is a japanese word pronounced sah-gay, meaning "to lower". Age (上げ) means "to raise".
>>
>>51621057
Is that like a frob?
>>
>>51621057
>>51620974
>>
>>51620455
I haven't tested it but you have to stop when the current->next = NULL otherwise you'll get a segmentation fault
And as an alternative you can always append at the front of the list, i.e., the new item goes to the first position, that way you don't have to traverse the list.
Or your adding functiong keeps a pointer to the last which is the same thing, with an inversed order
>>
>>51620861
> If you rely on process exit to do your memory management,
That's ambiguous.

I wouldn't generally recommend never freeing anything "because it will get freed on exit".

But I also wouldn't suggest bothering to free memory in the case where you're about to call exit() or abort().

If you're writing for mainstream desktop or server systems, you can take it for granted that the OS will recover resources (not just memory, but also open files etc). If you're writing for a non-mainstream platform where this isn't the case, there's no point asking /dpt/ about it.

But that doesn't necessarily help you, because there are other things the OS won't do, e.g. it won't remove temporary files or fsync() files or terminate child processes.

So in complex software, you generally need to write cleanup functions to match initialisation functions. And trying to figure out which ones need to be called on exit and which ones don't is usually more trouble than its worth.

This is why modern practice is to terminate the program by throwing an exception, because it ensures proper clean-up, whereas an actual C exit() will bypass all of that.
>>
>>51619755
setters make sense if you actually do some checking on the input to see if it's valid.
like
void setDay(int d) {
if(d > 1 && d < 31) // it fails miserably for february and months with 30 days but you get the idea
day = d;
else
throw someError();
}
>>
>>51620915
Then you still need to do cleanup so that you don't run out of the preallocated memory, even more so than if you're using the heap directly.
>>
>that moment you realize your code exercise might have gotten a little gay
touch balls.cc
>>
>>51620950
> You can implement a graph with n vertices as a nxn 2D array.
Only for a simple graph, not a multigraph (where you can have multiple edges between a given pair of nodes).

Also, array representation is inefficient for typical graphs, as the number of edges is typically significantly less than the square of the number of vertices.

It's more common to just store the set of edges. One common approach is to store two copies of the set, one sorted by the first vertex, one sorted by the second. This allows you to find all the edges for a given vertex reasonably efficiently using a binary search. The other common approach is to use associative arrays (e.g. hash tables), but these aren't part of the C standard library.
>>
File: 1447358415641.jpg (15 KB, 287x320) Image search: [Google]
1447358415641.jpg
15 KB, 287x320
Let's say I have something like this in C++
std::make_shared<example_object>

I wanted to do:
typedef std::make_shared<example_object> short_hand_t;

But this is not allowed with templates. I know there's aliases such as:
template<size_t N>
using vector = vector_array<size_t N, example_obj>;

But how do I do this without any template parameters? I tried
template<>
using short_hand_t = std::make_shared<example_object>;

But this didn't work. I don't want to add some stupid dummy variable either such as:
template<size_t dummy_var>
using short_hand_t = std::make_shared<example_object>;


Am I fucked? I definitely don't want to use #defines either.
>>
>>51621399
>>51621413
>>51621430

This is disgusting -- these trannies are WHITE.
>>
#include <iostream>
int main()
{
size_t t = SIZE_MAX;
malloc(t);
std::cout << "Memory is just a number." << std::endl;
}


Find a flaw.
>>
>>51621482
>penis photoshopped onto Nyomi Banxx

weak bait family
>>
the traps don't bother me, but tumblr? seriously?
>>
>>51621459
error: ‘SIZE_MAX’ was not declared in this scope
>>
I see the butthurt faggot finally figured out how to get around a ban
>>
File: ss+(2015-11-30+at+07.59.41).png (4 KB, 297x91) Image search: [Google]
ss+(2015-11-30+at+07.59.41).png
4 KB, 297x91
>>51621459
Lol it actually used less memory than Firefox with one tab open.
>>
>>51621459
SIZE_MAX not being declared beforehand?
>>
>>51621459
you forgot to include cstdint :^)
>>
>>51621525
>>51621515
>>51621544
>not using msvc
>>
>>51621543

Truly hideous, even for a tranny.
>>
>>51621553
>using MSVC
>>
>> 51621376
std::make_shared is a function, not a type, so you can't typedef it.

It seems as if you want:
typedef std::shared_ptr<example_object> short_hand_t;

so that you can do:
short_hand_t obj = std::make_shared<example_object>(whatever);
>>
File: smallocfrob.png (16 KB, 2150x226) Image search: [Google]
smallocfrob.png
16 KB, 2150x226
>>51621459
Made it even better!

Memory usage shot up to 3GB as soon as it started.
>>
What's microprogramming? I'm guessing instead of instructions like LDA, EXE, STA, etc. you're actually moving data between registers? Does anyone have an example of a microprogram?
>>
Do people seriously jack off to this shit?
>>
>>51621376
>>51621644
Alternatively:
std::shared_ptr make_example(/* args */)
{
return std::make_shared<example_object(/* args */);
};

auto obj = make_example(whatever);
>>
File: Screenshot_2015-11-30_19-11-43.png (34 KB, 724x333) Image search: [Google]
Screenshot_2015-11-30_19-11-43.png
34 KB, 724x333
>>51621658
Well, you did allocate about 2.3 GB
>>
>>51621399
>>51621413
>>51621430
>>51621448
>>51621467
>>51621481
>>51621482
>>51621499
>>51621518
>>51621543
>>51621564
>>51621581
>>51621598
THIS >>51619835
MODS please read, homo/tranny shit destroys /dpt/, no matter how innocuous it may seem
>>
What programming language should I start with for backend web development? Bonus points if you explain your choice.
>>
File: ss+(2015-11-30+at+08.12.58).png (24 KB, 1004x611) Image search: [Google]
ss+(2015-11-30+at+08.12.58).png
24 KB, 1004x611
>>51621733
>>51621658
Cleaned it up a bit and I'm now up to almost 9GB.

Soon this'll be almost as efficient as KDE!
>>
>>51621711
My notion of it and it might not be correct, is that you actually manipulate the hardware and you code new instructions like the ones the assembler already knows about like, add, load, bne, etc
>>
>>51621459
I wonder, could there be an exploitable security vulnerability in this program?
>>
>>51621742
I kind of hope the guy keeps it up until mods get fed up with it and start deleting and banning these shitty OPs.
>>
>>51621756
I doubt it.
>>
>>51621756
Doesn't look like it
>>
>>51621752
All right I think I've perfected it.

https://gist.github.com/anonymous/d651b832dd4040e26182

Upon execution, memory usage shoots up to 16GB (how much physical ram I have) and then continues to slowly crawl upwards. First test it got to 19.4GB before I killed it. Dunno how far it'll actually go.
>>
>>51621742
So you think they should capitulate? Just in this specific case, or whenever someone responds to posts they don't approve of by shitspamming?

Needless to say, if they have any sense, that's the last thing they'll do.

Troll OPs don't "cause" shitposting. Shitposters cause shitposting.
>>
whats the hardest part about learning ruby?

telling your parents youre gay
>>
>>51621837
Tranny OPs are against the rules in the first place.
>>
>>51620513
maybe I'll use go if/when it gets more libraries/helper functions
still not as comfy as python yet
simple shit, like uploading multiple files, is really complicated in go compared to python
>>
File: first time i launch my script.gif (2 MB, 460x273) Image search: [Google]
first time i launch my script.gif
2 MB, 460x273
>>51621746
python or ruby because hugely popular, everything you might need is already there for you
not java because cancer
elixir/erlang because they're fucking reliable (much more than your website needs to be tho)
hell even common lisp because it's great and it needs to grow its userbase
c# or f# if you like the Microsoft ecosystem
haskell if you're from CS background
>>
I am learning C++ and making a little loop program for the book I am reading.

I want to take two ints and do stuff with them. However I want to be able to read if the user types a | because that will end the program.

How the hell do I do that. Only learned python before that and there I could take in whatever check for the character and sanitize the input/change to an int after that easy.

I dont know much of C++ yet this chapter just introduced loops and functions if/than and switch statements plus vectors. I am sure I heard somewhere that not only is c++ missing an easy way to type check it is generally shit programming.

How the hell should I go about this I have tried a few things and keep getting problems.
>>
Hey DPT, Windows runs on ARM as well as x86, right? What is the "official" way that one is supposed to write a C or C++ program for ARM Windows?
>>
>>51621873
Noted, thanks.
>>
>>51621903
Unless you're doing hyper low level stuff, there shouldn't be any changes. Compile the source on an ARM machine and it should work.
>>
>>51621837
>Troll OPs don't "cause" shitposting. Shitposters cause shitposting.
seriously, tranny and anime (the non-acceptable, obviously provocative type) OPs DO cause shitposting.
>>
>>51621877
due to C backward compatibility a char is just an int
so you can have
char c = '|';
int i = c;
if(input == i)
//abort or exit
>>
File: DZE8fQG-1.jpg (63 KB, 242x321) Image search: [Google]
DZE8fQG-1.jpg
63 KB, 242x321
Let's say I need 100k threads to be running simultaneously. Is this too many threads? Let's say I've got a 12 core processor.

Pic related: the face of the hell I shall know trying to implement my own thread pool in c with longjmps
>>
>>51621945
Use Erlang.
>>
What's the maximum value of an unsigned long long integer in C++?
>>
>>51621962
I also need to use yacc and lex, so that's not an option
>>
>>51621975
Erlang can interop with C/C++ easily
>>
>>51621968
Nevermind I found it in the docs, it's just 0xffffffffffffffff.
>>
>>51621975
reimplement yacc and lex in erlang
>>
>>51621943

Ok thanks.
>>
>>51621968
std::numeric_limits<unsigned long long>::max()
>>
>>51621962
>Use Go.
FTFY
>>
>>51621945
> Is this too many threads?
Way beyond too many. The cost of context switch alone will prevent anything from running whatsoever. Anything more than roughly 2x core-count is going to reach the point where context switch takes more time than actual execution.
>>
>>51622029
"Go was a mistake." -Steve Jobs
>>
>>51622029
Go belongs in the trash. LFE/erlang/elixir are where it's at.
>>
>>51621938
> dogs > cats
#t
>>
just "finished" a couple-month project, biggest one I've done yet; now there is a void. I have two options: 1) new project 2) learn another language (I only know C and some C++ but have no interest in the latter)

wat
do

I have a couple ideas for a project.

1) A program that displays a small virtual robot in 2D top-down space that the user can program using an interpreted language built for controlling the robot. Perhaps it can be made into a game by having the goal to be to move objects into a goal area.
2) A simple and minimal GUI toolkit for creating programs with a GUI.

Languages wise, I don't know; I'm looking for employability, but not Java.
>>
>>51621873
Common lisp isn't a good language to attempt to boost the userbase of because it's stuck with a 1994 standard with no intent from anyone whatsoever to extend it in any way because "it's too much effort ;_; it costs too much ;_;". The community is also pretty awful: it's outright you're a cultist or you're an enemy. You're not allowed to like other lisp dialects, you're not allowed to think other lisp dialects have some interesting features, you're not allowed to dislike anything about lisp, you're not allowed to not praise the lisp2.

Racket is a more sensible choice but it has its own flaws (the awful typed-racket language for instance). Chicken would be great but it only has green threads and doesn't have 64-bit datatypes. They're both preferable to common lisp anyway.
>>
>>51622089
1- can be done in a few hours
2- could take months
Take your pick. You should use C++ for 1- and either C++ or C for 2- (only consider C because it allows you to provide an API that virtually any language can leverage).
>>
>>51621994
How so?
>>
>>51622089
Basing off of the idea for #2, you should write a C wrapper for gtk2hs, just to increase potential speed and efficiency of that framework.
>>
>>51622194
Have you really never heard of an FFI?
Beside that, most languages actually have modules that let them communicate with erlang programs using the spawn/pipe mechanisms.
>>
>>51622216
Why would he wrap a wrapper to a C library for C when he could just use the C library and why would he use a library that already implements what he's trying to implement?
>>
>>51622240
gtk2hs is wrtten in Haskell, not C.
>>
File: 1418226836357.jpg (37 KB, 251x242) Image search: [Google]
1418226836357.jpg
37 KB, 251x242
>>51618655

>learn to program
>without knowing how a computer works
>>
File: 1447396292065.jpg (126 KB, 1440x1080) Image search: [Google]
1447396292065.jpg
126 KB, 1440x1080
>>51622255
>>
>>51622226
No I've never heard of an ffi
>>
>>51622052
>LFE/erlang/elixir are where it's at.
https://news.ycombinator.com/item?id=10513445
>Haskell: 10GB for 500k websockets
>Phoenix: 83GB for 2M websockets
even meme langs are better than Elixir in terms of performance. want me to post links to the benchmark game site comparing Go and Erlang, for the n-th time?
>>
>>51622255
>>without knowing how a computer works

Now you've fucking done it. We're going to get EE fags in here going off about 'You don't know how a computer REALLY works!' and 'Without me, you'd be nothing!"
>>
>>51618416

Linked lists are pretty much useless these days except as a way to learn about datastructures.
>>
File: screenshot.png (1020 KB, 1366x657) Image search: [Google]
screenshot.png
1020 KB, 1366x657
Finished the back-end for now. Time to redo the UI.
>>
>>51621754
So a microprogram changes(?) the hardware to make new instructions?
>>
>>51619270

Why not just use a struct?
>>
File: 1442047946905.png (285 KB, 1200x1200) Image search: [Google]
1442047946905.png
285 KB, 1200x1200
>>51622276
>hacker news
>no information on what was even being compared
>>
>>51622285
What's that?
>>
>>51622285
Is that a frob?
>>
>>51622276
>hacker news
>gayming website

Come back with a peer reviewed journal article and maybe somebody will take you seriously.
>>
>>51622276
also, http://www.jayway.com/2015/04/13/600k-concurrent-websocket-connections-on-aws-using-node-js/
>When experimenting with this I reached 800k idle connections with a M3.2xlarge instance which gives you 8 CPUs and 30Gb of memory.

>>51622324
>>51622364
>being so useless, can't even click a second link
you guys call yourself programmers?
>>
>>51622354
Image/comic organizer. Kind of like a *booru, but with UI improvements (quickly filter and traverse images, keyboard shortcuts, etc.)
>>
>>51621943
>>51621877
Ok I cant figure this out. Anyone help? In the early part of the book and cant use a standard libraries or anything yet really.

#include "std_lib_facilities.h"

int main() {

char inpt1, inpt2;
int first, second;

while (1) {

cin >> inpt1 >> inpt2;
if (inpt1 == '|'||inpt2 == '|') break;

else {
first, second = inpt1, inpt2;
}

if (first > second) {
int temp = first;
first = second;
second = temp;
}
cout << "The smaller value is: " << first << " The larger value is: " << second << "\n";
}
return 0;
}


Its just spitting out random numbers now. But it does seem to be exiting upon |.
Thread replies: 255
Thread images: 36

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.