/dpt/ - daily programming thread

RIP Linked Lists (1956-2016) Edition

Old:

Other urls found in this thread:

infoq.com/presentations/Value-Values
vimeo.com/113588389
cvedetails.com/product/47/Linux-Linux-Kernel.html?vendor_id=33
en.wikipedia.org/wiki/String_searching_algorithm
stackoverflow.com/questions/3183582/what-is-the-fastest-substring-search-algorithm
twitter.com/SFWRedditImages

#include

typedef struct unit unit;
struct unit {
char *s;
unit *next;
};

#define cons(x, y) (unit[]) {{x, y}}

int main(void)
{
unit *lst = cons("this",
cons("is",
cons("a",
cons("compile-time",
cons("linked",
cons("list", 0)))))), *l = lst;
do {
puts(l->s);
} while ((l = l->next));

return 0;
}

Wow pretty cool! I've never thought of doing it like this before. Smart method

C users are dumb as shit

infoq.com/presentations/Value-Values

based HICKEY

>dat laptop
>dem stickers

is it true?

Sometimes. It pretty popular to write apps in JavaScript

partially

All the good apps are native
I have seen javascript apps, they are dogshit

another one
vimeo.com/113588389

There is no reason for manually allocating memory in 2016.

Let's be honest: most of us aren't as smart as we think we are. C code of a certain size will always be more leaky and bug ridden than Java of the same level of complexity. I would say that for everything other than low-level drivers, C should be considered harmful.

That's true, even people that are confident in their C skills make stupid mistakes that result in stack corruptions, buffer overruns and such.

>most of us aren't as smart as we think we are
especially arrogant C tards

>C code of a certain size will always be more leaky and bug ridden than Java of the same level of complexity
I'm fairly sure that you will find less bugs and memory leaks in the Linux kernel than fucking """"ANY"""" Java project consisting of 15 million lines of code.

stay delusional, and keep thinking you write linux grade C

What's the point of using a linked list if you know what elements you want at compile time and won't be adding or removing anything?

Try running valgrind /usr/bin/java on your command line and tell me what you see wrong. And that's just without running a program or anything. Just the stupid interpreter.

If you can't manage manual memory allocationyou shouldn't be programming.
And having a gc doesn't alleviate the need for thinking about resource management, especially when you start using non-heap type resources like files, locks, threads, etc.

Well, considering I have a patch that has been ack'ed and is awaiting approval for reasons other than code quality, I do.

>there isn't a reason to manually manage memory when writing CRUD enterprise Java apps
ftfy

Its not just mobile apps. Spotify's desktop client is javascript, for instance.

cvedetails.com/product/47/Linux-Linux-Kernel.html?vendor_id=33

It looks like a cool exercise. Doesn't have to have any practical use necessarily.

>If you can't manage manual memory allocationyou shouldn't be programming.
C tards can't even zero a 2d array, yet they insist on programming

>denial of service constitutes over 50% of vulnerabilities
It pretty much confirms what I said, when did DoS have anything to do with code quality and not the protocol being used?

>C tards can't even zero a 2d array
memset

uhhh learn what DoS means

yes, but some delusional fucktard in the previous thread insisted on that it was UB

Denial of Service
Disk operating system
???

you can also use bzero

Yes, when doing it on a pointer to pointer, like the original user asked.

Probably a webdev then.

Why is it that an HttpUrlConnection's connect method finishes quickly if I'm stepping over it in the debugger while it's taking forever for it to finish if I'm running the program normally?

>inb4 >Java
Yes, I know I'm using Java, but I'm somewhat of a beginner, so cut me some slack here. I haven't gone that far in learning C so as to use a third party library like libcurl to do some simple network operations.

(you)
(you)

he fucking didn't, see for yourself , it's just your shitty assumption that your self-centered arrogant fuck decided was the objective truth

> Double free vulnerability in drivers/net/usb/cdc_ncm.c in the Linux kernel before 4.5 allows physically proximate attackers to cause a denial of service (system crash) or possibly have unspecified other impact by inserting a USB device with an invalid USB descriptor.

literally memory corruption is considered a DoS
now piss off fag

>cant answer the original question
>gives answer to a different question
>autistically tries to claim that it answers what the person asking really meant to ask
This is why I stopped posting in the /dpt/

this

it depends, if it's a pizza ordering app or uber of course it involves web shit (server access over the interwebs), but even for those apps it helps with responsiveness and battery drain if as much as possible of the app is in native code and not browser cancer

serious games should of course be in native code, not in web cancer shit

>he fucking didn't
He did:

You don't need GC to eschew manual memory management, though.

>now piss off fag
First post source that a 15M LOC java project will have less bugs.

yeah you sure stopped posting in /dpt/, we can clearly see that

that's not necessarily him, and anyway see it's a fucking trivial topic

What exactly is this image measuring? Insert? Pushback? Iteration?

nuh, it runs on a custom ui framework made by spotify. it's called spider or something like that

Learned about interval trees, then figured out they could be used to store IP address ranges (not in CIDR notation, but actual start and end addresses). Spent hours hacking away and what I created was a thing of beauty. Inserted 2000 IP ranges into the tree and then brute-force checked all 2^32 IPv4 addresses just to see that it works. Yes, even the addresses that actually cannot be used. It worked beautifully, the whole test took about 2 minutes and after hours of checking and more testing, I didn't see a single failure. This was all in C++11.

Then I designed a way to store the tree on disk and only load the parts of it that are actually needed. Slower, but still quite fast.

Then I started to actually write the PHP script that needs to read that file and check if the visitor's IP address is in the tree. It didn't work, because PHP can't deal with unsigned integers and any IPv4 address that's 128. or bigger is a negative integer in PHP. So the tree didn't work, because the negative integers broke the comparison and wrong tree branches got selected. Back to the drawing board.

So then I split the one big tree into 256 smaller trees. I use the first octet to choose the tree, then use the remaining 24 bits to check if the address is in the tree. 24 bits won't overflow, so it actually works. PHP is too slow to check the all 2^32 addresses, but the C++ version works, so I believe the PHP version works too. I did check 100000 random addresses and it didn't fail even once.

Phew.

I hate PHP, but I don't have a choice.

I'd love to do this with IPv6, but the hosting service has no idea what that is, so it'd be a waste of time now. Maybe later.

can't find any so I guess I won

>that's not necessarily him,
I believe it is.

>and anyway see
We already covered this, this relies on sizeof(int) being smaller than sizeof(int*) and it's fairly shitty solution to allocate more memory than you need.

>it's a fucking trivial topic
So is averaging two ints, but yet no one here is able to do it.

lol wut

you can use pointer arithmetic, the same as you would do with array access, so it doesn't matter what the sizeof(int*) is RETARD

You can also just allocate a 1D array and access it doing arithmetics too, instead of storing both pointers and values in the same linear chunk of memory. I don't know why on earth you would think that was a good solution at all?

...

>i can't find proof of what i claimed therefore i won
Sounds about right

the retard insisted on having a dynamic memory contiguous 2d array so that it could be zeroed with one memset

either you use proper fucking 2d arrays FOR FUCK'S SAKE or you use a trick like that if you insist on having a malloced """"2d array"""" in contiguous memory

>the retard insisted on having a dynamic memory contiguous 2d array so that it could be zeroed with one memset
No, he didn't.

All he said was that he had an array allocated as int** and asked how he could do it more efficiently than a nested for-loop. My first reply was "change it to a 1D array and do memset instead" and then you started going off like a retard crybaby about it works on 2D arrays too but not when you malloc and how 2D arrays are not 2D arrays after all and all sorts of retarded shit.

also the int** solution with numerous different malloc'd memory also has extra memory for the pointers

a dynamic memory array of arrays is not the same as a 2d array, 2d arrays work perfectly fine with memset

Autism

int **ptr;
pointer to pointer to int

int arr[m][n];
2d array

retard

stop hurting me

>if you create a 2D array in dynamic memory that's not the same as creating a 2D array because I'm trying to redefine arrays using my arbitrary definition so my original reply doesn't sound so stupid

kill yourself idiot

Automatic memory management is fit only for servers, where stuff will run for months and doesn't have to react to input in real time manner. Application software is the opposite of that, even a few leaks are fine if the UI does not stutter.

lol, why are you getting so emotionally invested in this? Your answer is perfectly valid had the original user allocated the array that way, but he clearly stated he hadn't, so why are you so upset over this and spend fucking 60 posts trying to say "oh, but you see, YOU are WRONG" instead of saying just "oh okay, then do this instead"

The autism displayed on this board never ceases to amaze me.

>why are you getting so emotionally invested in this?
Because he's 12 years old

Now stop replying you fucking autist.

my initial reply to (You) was perfectly reasonable, from the context provided there was nothing that mandated converting it to a 1d array, fucking retard

Memset a 2d array? Like, "array of arrays" array? C doesn't have continuous 2d arrays so you'll have to use it in a loop, which defeats the whole purpose. When combined with allocation it's just one more line though.

>from the context provided there was nothing that mandated converting it to a 1d array, fucking retard
>from the context
You were assuming that user had created an array of contiguous memory. I were not. My suggestion would work in both cases, "fucking retard"

even if you memset in a loop in a pig disgusting malloced array of arrays, it's still the same (or more efficient) as setting the values normally, there is no problem here

kill yourself, your answer was shitty and would lead to extra work and make his program shittier for no real reason, your post had caveats that you didn't explain

>most of us aren't as smart
yeah, you're pretty dumb actually; leave C to the pros with big dicks

Also, none of these are my posts anyway, so why list them?

because they started the entire shitty debate, the fucking ridiculous claim that it was UB to memset a 2d array

To check whether something is in a some kind of set, use the bloom filter. Isn't interval tree rather used for prefix sums?

>it triggered my autism
Gotcha

Btw, memsetting an int** does in fact cause a memory leak.

How would I go about finding location of string in a file? I know that given string exists in that file only once. So far I tought about reading n bytes, where n is the length of string, starting from offset 0 and iterating one by one untill you find that offset where that string is located.

i was talking about an array, as implied by the variable name 'array', not an int**

>your answer would lead to extra work and make his program shittier for no real reason
So would change his allocation to being stack allocated of fucking FIXED SIZE retard.

>inb4 VLA
Those are hardly implemented in C99 implementations, and it's only optional in standards after C99.

en.wikipedia.org/wiki/String_searching_algorithm
stackoverflow.com/questions/3183582/what-is-the-fastest-substring-search-algorithm

>C doesn't have continuous 2d arrays
you dumb, nigga? 2d arrays can only be continuos in C

for most problems it's fine to have a fixed size array, you don't know what he's doing

Are you seriously so retarded that you get confused if someone does this: int** array;?

>bawww it's not a real array
Except it is (can be, if you're going to be technical) due to pointer arithmetics, the only difference is how they are allocated.

>Let's be honest: most of us aren't as smart as we think we are.
Speak for yourself.

Some people write code more advanced than shitty fizzbuzzes, you know.

you're wrong, for example an array can degrade into a pointer, but a pointer can't "degrade" into an array

>hardly implemented
>what is gcc
>what is clang
>what is icc
user...

kill yourself retard

They fucking aren't? They are one dimensional arrays of pointers. C# has real 2d arrays, as well as "array of array" arrays, they have different syntax and really are a continuous chunk of memory, not scattered around the heap.

what is this then

int array[8][8];

>icc
You need to compile as C++ in order to get it to work in icc, and as for gcc and clang they will spit out warnings.

That seems to be your go to reply when you are stumped. Let me remind you that you need to be 18 to post here.

>Except it is
it isn't
arrays don't "degrade" into anything

>go to /dpt/
>want to read comfy programming discussion
>70/88 posts are bait and calling each other names
why?

>hurr durr all multi-dimensional array problems fit on the stack

You guys are retarded.

>Some people write code more advanced than shitty fizzbuzzes, you know.
yeah what a useful response, retard, sure got me stumped

kill yourself

>They fucking aren't
they are tho, you don't know C
>continuous chunk of memory
just like in C

auto array = new int[m][n];

>hurr durr

>You need to compile as C++ in order to get it to work in icc
wrong
>and as for gcc and clang they will spit out warnings.
no, they won't

Show me the code that produces a continuous 2d array on heap.

not C

what the hell are you talking about 2016? People have known about this since like 2008

the original questioner included C++