[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 315
Thread images: 23

File: 1480590811928.png (389KB, 934x1000px) Image search: [Google]
1480590811928.png
389KB, 934x1000px
What are you working on, /g/?

Old thread: >>59556199
>>
File: K&R hime2.png (1MB, 1280x720px) Image search: [Google]
K&R hime2.png
1MB, 1280x720px
First for C!
>>
I sure am glad I joined fucking /dpt/'s discord where they're making jokes about texmex being like sex and posting images of dogs and arguing about functional programming type trivialities for like 2 hours at a time
>>
second for c++17
gcc 7 when?
>>
>>59561074

because you have to do that if you want to treat it as an array that does automatic pointer arithmetic you slut
>>
>>59561074
First for C is SHITE
>>
>>59561080
>/dpt/'s discord
No such thing.
>>
Reporting bugs in Ubuntu's X server and getting them closed as WONTFIX even though ubuntu just shits on the spec and doesn't give a shit.

Fuck me they are doing their best to become the new Microsoft with their "Compatibility over correctness" attitude.
>>
>>59561114
whatever presents itself as such is that thing if no alternatives are presented
>>
>>59561080
>discord shill trying to fit in
Fuck off.
>>
File: getdelim.png (80KB, 880x620px) Image search: [Google]
getdelim.png
80KB, 880x620px
>>59561036
yes

but to me the most triggering part of GNU code is the consistently inconsistent whitespace

pic related, just opened a random glibc source file and there it is
>>
>>59561080
Then why the fuck are you here? Go back to your gaming chat idiot
>>
>>59561118
> Ubuntu's X server
Report in other X servers
>>
Anyone here use JavaFX? I have a problem and I can't find the answer. I'm using the Main, Controller, and .fxml method of making my program. I have two windows, the primary window contains a button that is supposed to show the secondary window.

What I want to do is create a method that shows the window and assign that to the button using the controller class. Like so:
 public void showSubWindow () {
anotherStage.show();
}

However the anotherStage doesn't exist in the Controller class, and I have no idea how to get it over to controller. Does anyone know how? Thanks.
>>
What makes endless layers of C preprocessor macros?
>>
File: 1476541970626.jpg (101KB, 901x1201px) Image search: [Google]
1476541970626.jpg
101KB, 901x1201px
>>59561080
>>>/v/
>>
>>59561125
>>59561134
Sarcasm, retards.

The Discord is shit, and is the only reason why tripfags don't post in /dpt/ that much anymore because they're busy spamming their wrong opinions about Haskell, C, and Java there.
>>
>>59561097
I don't even mind many macros, I just hate being sent on a wild goose chase looking for the actual implementation of anything only to find each individual step of the implementation similarly obfuscated and scattered among a dozen header files.
>>
>>59561183
>>59561126
>C
Found your problem
>>
>>59561152
Lack of features like polymorphism leading people to reinvent them using messy macros.
>>
>>59561152
there's nothing wrong with CPP
>>
>>59561080
link?
>>
>>59561189
sloppy use of whitespace is not really language specific
>>
>>59561218
eh? Do you have any official tool like Cfmt?
>>
>>59561194
And what do they make with macros?
I want to learn all levels of preprocessing.
>>
>>59561218
A format tool can solve this problem
>>
>>59561225
The GNU people apparently don't.

>>59561232
Then why does every GNU file look like >>59561126

(note: the arrows are tabs, the dots are spaces)
>>
Dropped a freelance project because it didnt give me time to work on my C pet project
NEET 4 life
>>
>>59561227
>I want to learn all levels of preprocessing.
Why.
Modern languages are moving away from them for a reason
>>
>>59561256
>Then why does every GNU file look like this
Probably because C doesn't have any language server or format tool
>>
>>59561263
I want to become horrified and drop C entirely
>>
>Tabs MUST be used for indentation instead of spaces
>Tabs SHOULD be 4 spaces
Anyone who disagrees is a pathetic cuck.
>>
>>59561276
>drop C entirely
Then do it right now, theres plenty of better choices.
>>
>>59561295
I am not horrified enough yet
>>
>>59561292
Already do that
>>
>>59561305
C codes are unreadable and it induces vomit.
>>
>>59561305
>I am not horrified enough yet
Go look at any large FOSS base in C.
Thats your future.
>>
>>59561202
https://discord.gg/6g7MM
>>
>>59561330
>>59561202
Just fuck off, shill
>>
>>59561227
>And what do they make with macros?
Everything.

Basically the main reason to use macros other than the obvious (MUHCONSTANTS) is performance - a macro doesn't create a stack frame like a function call does. You're moving that overhead from runtime to compile time.

This was doubly important before C99 when "inline" wasn't a thing, but even now that's just a suggestion for the compiler.
>>
Why are video gamers shitting on this thread?
>>
>>59561292
I do this but 2 spaces.
>>
>>59558029
>>59561062

#include <stdio.h>
#include <math.h>

int main()
{
unsigned int nums[] = { 512, 20, 5, 21 };
int len = sizeof(nums) / sizeof(nums[0]);

unsigned int n = 0, digits = 0;

for (int i = len - 1; i >= 0; i--) {
n += nums[i] * (unsigned int)pow(10, digits);
digits += log10(nums[i]) + 1;
}

printf("%u\n", n);

return 0;
}
>>
>>59561295
Name one better choice if you're writing an OS.

And if you're not writing an OS, what the fuck are you even doing here.
>>
>>59561354
Rust
>>
>>59561354
Assembly
>>
>>59561354
>And if you're not writing an OS, what the fuck are you even doing here.
Same reason you are here, not writing an OS
>>
>>59561354
Python
>>
>>59561354
>And if you're not writing an OS, what the fuck are you even doing here.
Woah there we got an (((exper))) turbo C kernel haxor in our midst
>>
>>59561354
>And if you're not writing an OS, what the fuck are you even doing here.
Literally 1% of /dpt/ are probably doing anything like that let alone making any major commits to a distro/kernel.

And why dont you show us what youre working on
>>
>>59561292
>4 space shitter
If you use anything other than 8 space tabs you are shitter who should be never let anywhere near code that somebody has to read.
>>
>>59561385
You mean 0%
>>
>>59561391
I do 32 spaces bro
>>
>>59561395
Well I was being generous.
>>
>>59561391
That's like, you're opinion man.
But 4 is the sane default. 2/8 are also acceptable.
>>
>>59561409
If you are not on 32 spaces you should die
>>
>>59561341
Are there examples with two layers of preprocessing?
>>
>>59561391
>he needs to turn his head 90 degrees to the right to follow indentations
>>
>>59561292
>Tabs MUST be used for indentation instead of spaces
I use 4 spaces. What's wrong with spaces? Consistency all throughout.
>>
File: 1476040774458.png (1MB, 1204x1204px) Image search: [Google]
1476040774458.png
1MB, 1204x1204px
Good lord I don't have to indent the code.
>>
>>59561436
>writing lines longer than 80 character
fucking web devs
>>
>>59561152
There's valid and tangible reasons why you would make heavy use of the C preprocessor.
>>
File: Untitled-1.png (475KB, 920x893px) Image search: [Google]
Untitled-1.png
475KB, 920x893px
>>59561468
>fucking webdevs
>why won't they use the same spaces as me
>>
>>59561475
> There's valid and tangible reasons
Name them!
>>
>>59561098
>doesn't know how C's type system works

>>59561292
I agree, unless your code needs to be put on punch cards.

>>59561317
>codes
>>
>>59561487
What type system?
>>
>>59561485
Post an example of "c preprocessor abuse" and I'll explain why it's necessary.
>>
>>59561468
>not keeping your code to 72 columns so it can be read in TUI terminal editors
>>
>>59561050
wait I'm not on /lit/ wtf am I doing here
>>
>>59561468
How would you do that in street shitter languages like Java or C# that HaveLongFuckingSentencesThatAreAlmost80CharsByThemselves.
>>
>>59561487
>not codes
Got any better p̶o̶l̶i̶t̶i̶c̶a̶l̶l̶y̶ ̶c̶o̶r̶r̶e̶c̶t̶ /dpt/ "approved" phrase for that?
>>
>>59561468
I don't, my .vimrc is configured to break at 79. Which is exactly why 8 space tabs are a waste of space, and also tabs in general, as someone editing your code with different tab layout will be under/over 80 characters.
>>
>>59561118
fuck ubuntu
>>
>>59561505
XD looks like I'm in the weird part of 4chen again
>>
>>59561502
C identifiers are compile-time constructs whose type is immutable. If you declare an identifier as "int a", there is no way you can make that identifier a double or a char. The block of data the identifier refers to can be accessed as different types, either using pointers or anonymous access in an expression, but the identifier's type can't be changed. Thus, writing char a = malloc(2) means the result will invariably be stored as a char. There's simply no way to change that, even if you cast it to some other type in between.
>>
>>59561487

k bitch
>>
>>59561502
C has a type system?
>>
>>59561391
4chan does 4 spaces, your opinion is invalid.
>>
>>59561559
it was just a joke lad
>>
>>59561587
>4chan
Who is this guy again?
>>
I've been trying to learn Haskell. The wikibook was fine until I ran into folds, so I went to "Haskell programming from first principles" and am more than 200 pages in without understanding the practicalities and uses of the principles being taught.

Is there a better resource to learn Haskell, or should I just stop my bitching and go back to the wikibook?
>>
>>59561391
3 spaces are the only true way to indent.
>>
>>59561604
Some faggot weeb, don't pay him any mind.
>>
I'm learning m4 macro. That shit is crazy.
>>
>>59561616

the first thing to do when you want to learn haskell is compile UberStudent Plato with -O2
>>
>>59561632
For what purpose?
>>
>>59561616
The wikibook is best
What problems are you having with folds?
>>
>>59561503
https://github.com/Philpax/binarycpp/blob/ec87c09088eacc2b95ff7a8b35093cb0176afdd6/main.c
>>
>C preprocessor macros

oh boy

actual Bourne shell code snippet:

ADDRESS    alloc(nbytes)
POS nbytes;
{
REG POS rbytes = round(nbytes+BYTESPERWORD,BYTESPERWORD);

LOOP INT c=0;
REG BLKPTR p = blokp;
REG BLKPTR q;
REP IF !busy(p)
THEN WHILE !busy(q = p->word) DO p->word = q->word OD
IF ADR(q)-ADR(p) >= rbytes
THEN blokp = BLK(ADR(p)+rbytes);
IF q > blokp
THEN blokp->word = p->word;
FI
p->word=BLK(Rcheat(blokp)|BUSY);
return(ADR(p+1));
FI
FI
q = p; p = BLK(Rcheat(p->word)&~BUSY);
PER p>q ORF (c++)==0 DONE
addblok(rbytes);
POOL
}
>>
>>59561660
To generate a Makefile.
>>
>>59561507
Just call it code, because code is a mass noun in that context. It refers to a collection of programming statements/expressions/lines/instructions, individually you wouldn't refer to each one of those as "a code". It's okay to refer to something as "a code" if it's a discrete unit of numerical representation of non-numerical information, such as CPU opcodes or control signals in a server/client protocol.
>>
>>59561682
automake isn't so hard that you need to learn m4.
>>
>>59561675
AH YES ALGOL WE MEET AGAIN
>>
>>59561141

JavaFX is deprecated use Swing
>>
>>59561696
auto* is shit
>>
>>59561423
# define weak_alias(name, aliasname) _weak_alias (name, aliasname)
# define _weak_alias(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
>>
>>59561723
What other makefile generator, or really any program, uses m4?
>>
File: 144957358273.jpg (7KB, 249x243px) Image search: [Google]
144957358273.jpg
7KB, 249x243px
>>59561675
ALGOL-C is best C
>>
>>59561716
Elaborate?
>>
>>59561739
* or just take a look at this

https://github.com/lattera/glibc/blob/master/include/libc-symbols.h
>>
File: .png (579KB, 781x739px) Image search: [Google]
.png
579KB, 781x739px
>>59561364
>>59561366
>>59561372
>>59561375
>>59561381
>>59561385
>he knows how to invoke hte maymays
>>
File: not_even_mad.gif (2MB, 355x185px) Image search: [Google]
not_even_mad.gif
2MB, 355x185px
>>59561675
LOOP
// foobar
POOL
>>
File: memories.png (79KB, 1165x714px) Image search: [Google]
memories.png
79KB, 1165x714px
>>59561050
still doing memories.
>>
>>59561742
???
>>
>>59561849
Follow the chain of posts

>learning m4
>why?
>to generate makefiles
>don't need to know m4 to use automake

Then I guess you're not him with >>59561723, I thought you were so I asked what other program but automake uses m4.
>>
Okay so can /dpt/ give me any examples of GOOD codebases in C?
>>
>>59561930
openbsd
>>
>>59561930
oxymoron
>>
>>59561930
SQLite is top notch, clean, clear, well commented, extremely stable. Neatest C code base I know. If we could clone Hipp a thousand times C would be saved.
>>
>>59561901
I am >>59561849 and >>59561723

>other program but automake
other program imply not automake, so your sentence is hard to understand.

Sendmail use m4 too
>>
>>59561930
definitely not linux
>>
I hate Pascal.
It's too structured.
>>
>>59562079
So you're learning m4 to generate makefiles, like using m4 as a preprocessor to your makefiles? Why? That sounds absolutely horrible.

If not, how are you generating these makefiles with m4?
>>
File: 149020586933.gif (328KB, 500x517px) Image search: [Google]
149020586933.gif
328KB, 500x517px
Is Lua used in big projects?
>>
Does anyone know how to get the duration of any media file (mp3, m4a, wav) in c#, wpf? I could only find one solution online that is (ab)using a MediaElement for it. This can't be the only way, can it?
>>
>>59562158
not as the backend
>>
File: 1200px-Kopimi_k.svg.png (65KB, 1200x1250px) Image search: [Google]
1200px-Kopimi_k.svg.png
65KB, 1200x1250px
Why shouldn't I release my software with this license
>>
>>59562158
awesome wm is ~50% lua
>>
>>59562158
Apart from scripting games?

https://en.wikipedia.org/wiki/Category:Lua-scriptable_software

Doesn't seem like much, but yeah I guess.
>>
>>59562158
Garrys Mod
>>
>>59562140
>like using m4 as a preprocessor to your makefiles?
Exactly.
>Why?
Because the generated Makefile is so beautiful.
>how are you generating these makefiles with m4?
m4 Makefile.m4 >Makefile
>>
>>59562210
Whatever you want friend but I don't see why m4 would be required. You can do a lot in pure make and there's a shitload of makefile generators(or alternative build systems) available.
>>
>>59562248
>Whatever you want friend but I don't see why m4 would be required.
If I don't use m4, it's sed. sed is OK for minor things, not major.
>You can do a lot in pure make
I had a Makefile, but it annoy me to see mention of nt when on Linux, or the opposite. Now, when I look at the generated Makefile it's fucking pure.
>makefile generators
They're all shit.
>>
>>59562180
That's a png file.
>>
>>59561718
Other way around.
>>
>>59562173
You can probably find a wrapper to libavcodec(ffmpeg).
>>
>>59562330
Or that might be libavformat. Whatever, the ffmpeg shit.
>>
>>59561266
clang-format does the job. Of course the GNUtards wouldn't use anything LLVM related.
>>
>>59562454
indent is old as fuck, I think it came from berkeley. Even GNU indent(which defaults to very loved GNU style) predates that by almost 20 years.
>>
>>59562528
I'm quite sure indent is no longer developed and doubt it'd work with the C++ code base that GCC is. But the point was that saying there is no formatting tool for C family languages is stupid.
>>
>>59562304

No
>>
I need to broadcast a message to all clients connected to my server. How do you do that with sockets in C
>>
>>59562776
a loop
>>
Programming is hard.
>>
>>59562776
Multicast is a thing that exists, but no one fucking uses that, so basically this >>59562799
>>
>>59562799
So it'd be fine to just send it to each one in a for-loop? (Doesn't have to be exact. A few seconds delay is fine)
>>
>>59562808
maybe you're just dumb.
>>
>>59562832
Really depends how your server is set up. Do you have a thread for each connection or are you doing select() or what?
>>
>>59562836
That's why programming is hard.
>>
>>59561050
dsktps.net is a nice site to get wallpapers so i wrote a script to get all

from bs4 import BeautifulSoup
import requests
import urllib
import os

try:
os.mkdir('downloads')
print 'Created directory...'
except OSError:
print 'Directory already exists. Continuing. '
pass

os.chdir('downloads')

page = 1
while page <= 25:
req = requests.get('http://www.dsktps.com/color/all/page' + str(page))
soup = BeautifulSoup(req.content, 'html.parser')
photos = soup.find_all('div', {'class': 'archive-container'})
for photo in photos:
href = photo.find('a', href=True)['href']
photo_page = requests.get(photo.find('a', href=True)['href'])
content = BeautifulSoup(photo_page.content, 'html.parser')
listings = content.find_all('div', {'class': 'listing'})
for listing in listings:
img = listing.find('a')['href']
if '2880x1800' in img:
urllib.urlretrieve(img, img.rsplit('/', 1)[-1])
page += 1
>>
>>59562862
I'm using a 3rd party library which uses libevent to do "onconnection", "onmessage", "onclose" etc. callback functions so I'm not sure how it works under the hood.
>>
>>59562883
I just find 1 or 2 wallpapers I like and then start a thread on /wg/.
>>
What all goes into a header file?

I know you define structs there, put in all the method signatures, what else?
Do you put in any "global" variables there too?
>>
>>59562904
a loop.
>>
>>59562924
headers = declarations, macros, etc
source = definitions

Glad I moved away from that antiquity though.
>>
>>59562924
http://c-faq.com/cpp/hfiles.html
>>
>>59562951
Yeah, I'll go for that then. because the wait event actually halts the program until some kind of kill signal is sent, I have a second thread which is the broadcasting thread (sends data every second). I guess I'll just put a for loop inside a while loop there.
>>
I need some javascript help.

I've got one array that's just a bunch of people's names. What I want to do is use some kind of loop to generate a number for each name, and then put all those numbers in a different array.
How would I go about doing this?

any help is appreciated
>>
>>59563074
>a number for each name
Can't you just the index into your array?
>>
>>59561074
c toddler.....
>>
I know or rather knew C.
The last time I used it was 4 years ago,
so I forgot a lot of shit probably.
Now I need to use it again.
What is some quick, short guide to get up to par again?
Nothing extensive, but something that covers everything more or less briefly, not just the basics.
>>
>>59563092
I want it to be a random number 1-100
>>
>>59563097
If you knew C you wouldn't have forgot it.
>>
>>59563100
You could hash the string and mod 100 it. But you're going to have collisions which you probably will need to resolve.
>>
>>59563100
(rand % 100) + 1
>>
>>59563103
Please answer my question.
I did not really forget it, but I want to be sure that I did not forget anything, for which a short guide would be ideal.
>>
>>59563097
>>59563132
Just skim over K&R or something.
It's not like it's a particularly long book.
>>
>>59563132
What parts are you unsure of?
>>
>>59561080
Glad to have you too anon~
>>
https://www.youtube.com/watch?v=jIjPTuekCcM
How do I into stuff like this?
>>
>>59563147
It's pretty long in my opinion.

>>59563153
Mostly best practices, libraries, and some syntax.
>>
>>59563202
Best practice is subjective, although you might read style guide like:

http://lxr.free-electrons.com/source/Documentation/CodingStyle?v=4.0

Libraries, it's extensive but there's glibc manual or the standard. man pages work too.

For syntax, K&R would probably work. But that's ancient ANSI syntax, just write programs.
>>
>>59563263
Ah, linux coding style guide seems good, since I will work with linux drivers.
Thanks.
I mostly remember C-like syntax, so it ok.
>>
has quicklisp switched to https yet
>>
>>59563263
>Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you're screwed anyway, and should fix your program.
What did Linus mean by this?
>>
>>59563456
If you need more than 3 levels of indentation *within a function*.
>>
>>59563524
Well you already have 1 indent from a function, then a loop and an if inside the loop. That's 3, that's the limit?

Seems small. What if you need to run that loop conditionally? Do you need to move it to another function?
>>
>>59563567
>you already have 1 indent from a function
This is why I said "within a function". That doesn't count.

>then a loop and an if inside the loop
Why would you use a loop instead of a lambda expression?
>>
>>59563594
Because C doesn't have lambda expressions.
>>
ninja turtles 3
>>
Trying to delete an entire singly linked list, keep getting segmentation faults.

typedef struct node_struct {
char* data;
struct node_struct* next;
} node;

void clear()
{
node *ptr, *temp = head->next; //Head never holds data, it just points to the first node that does
while(temp != NULL) {
temp = ptr->next;
ptr->next = temp->next;
free(ptr->data); //Used malloc when assigning to this
free(ptr);
ptr = temp;
}
}


If I have 1 element and try to run it, it goes all the way until it hits free(ptr), then crashes out with
>invalid pointer: [pointer address]

If I have more than 1 element, it faults out at temp = ptr->next
I feel like I'm just making a really stupid mistake here.
>>
>>59563655
You never initialized ptr.
>>
Anyone want to look at my shitty C code? I'm doing exercise 6-2 from Pointers On C, and want to delete substr (el) from str (hello would become hlo) without using subscripts and string libraries:

#include <stdio.h>

int del_substr(char *str, char const *substr)
{
char *p_sub = substr;
char *p_str = str;
int match_found = 0;
int count = 0;
for(; *p_str != '\0'; ++p_str) // Find if the substr is in str.
{
char *pp = p_str; // This allows me to iterate on str from 1-n, then 2-n, etc.
while (*p_sub++ == *pp++)
;
if (*p_sub == '\0')
{
match_found = 1;
break;
}
/* If p_sub does not point to a null character then a match was not
* found, reiterate through the substr. */
p_sub = substr;
count++;
}

if (match_found)
{
p_str = str;
while (count-- > 0) // Gets in position for where the substr begins in str.
++p_str;

p_sub = substr;
while (*p_sub++ != '\0') // Skip over the characters to be deleted.
++p_str;

while (p_str != '\0') // Copy the remaining characters into original string.
*str++ = *p_str++; // Breaks here, IDK how to copy characters.

return 1;
}
else
return 0;
}


int main(void)
{
char a[] = "hello";
char b[] = "el";
del_substr(a, b);
return 0;
}


It was a big revelation from last thread to realize the difference between mutable/immutable with the difference of char[] and char*, but I'm still getting stuck.
>>
>>59563666
Changed it so both pointers get their own line for declaration.
Weird, thought C supported multi-variable inits like that.
Properly clears everything out now, but it does still crash at the end like temp isn't being properly set to NULL and the check is failing
>>
>>59563609
>Because C doesn't have lambda expressions.
LOL
>>
>>59563708
void free_list(node *ptr)
{
while (ptr != NULL) {
node *temp = ptr->next;
free(ptr->data);
free(ptr);
ptr = temp;
}
}
>>
>>59563708
>Weird, thought C supported multi-variable inits like that.
node *ptr = head->next, *temp = head->next;

would work.
>>
What's good some Lua program source to learn?
Can Lua be compiled or it's interpreted-only?
>>
>>59563744
Well don't I look the fool now.
Thank you
>>
>>59563706
Use valgrind.

$ c99 -Wall -g delet.c
$ valgrind ./a.out
==1182== Memcheck, a memory error detector
==1182== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==1182== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==1182== Command: ./a.out
==1182==
==1182== Conditional jump or move depends on uninitialised value(s)
==1182== at 0x400506: del_substr (delet.c:14)
==1182== by 0x4005D6: main (delet.c:49)
==1182==
==1182== Invalid read of size 1
==1182== at 0x40058B: del_substr (delet.c:36)
==1182== by 0x4005D6: main (delet.c:49)
==1182== Address 0xfff001000 is not stack'd, malloc'd or (recently) free'd
==1182==
==1182==
==1182== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==1182== Access not within mapped region at address 0xFFF001000
==1182== at 0x40058B: del_substr (delet.c:36)
==1182== by 0x4005D6: main (delet.c:49)
==1182== If you believe this happened as a result of a stack
==1182== overflow in your program's main thread (unlikely but
==1182== possible), you can try to increase the size of the
==1182== main thread stack using the --main-stacksize= flag.
==1182== The main thread stack size used in this run was 8388608.
==1182==
==1182== HEAP SUMMARY:
==1182== in use at exit: 0 bytes in 0 blocks
==1182== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==1182==
==1182== All heap blocks were freed -- no leaks are possible
==1182==
==1182== For counts of detected and suppressed errors, rerun with: -v
==1182== Use --track-origins=yes to see where uninitialised values come from
==1182== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
>>
>>59563898
Does valgring work for all executables made by GCC?
>>
>>59563760
"Programming in Lua"

Any language can be compiled or interpreted
>>
>>59564047
Yes but it's a platform thing, basically it just doesn't work on windows.
>>
>>59563706
>char *p_sub = substr;
You're discarding const here.

p_str += count;

>while (*p_sub++ == *pp++)
> ;
>if (*p_sub == '\0')
This is reading 1 past the end of the buffer.
Consider the situation where it's reading the null character in p_sub.
*p_sub == '\0' and *pp == something else.
So the comparison fails, and then p_sub is incremented PAST the end of the substring, and then the if statement is accessing invalid memory.
There are a couple of ways to fix this. You could just move it back with --p_sub
while (*p_sub++ == *pp++)
;
if (*--p_sub == '\0')

or you could remove the ++'s from the loop condition
while (*p_sub == *pp) {
++p_sub;
++pp;
}
if (*p_sub == '\0')

The first is shorter, but I would consider the second one to be cleaner.

>if (match_found)
>{
> ...
>}
Consider this whole block, there are a few things going wrong there.
In the first 2 while loops, you're incrementing p_str both times, which is not what you want.
The first one should set str, and the second one should set p_str.
str += count; // We can just use pointer arithmetic here. No while needed

p_str = str;
p_sub = substr;
while (*p_sub++ != '\0')
++p_str;

Now they are pointing in the correct places for the next block.
>while (p_str != '\0')
You're comparing a pointer to an integer here.
It should be *p_str.

Also, you need to null terminate your now shorter string, otherwise the old contents will be there, giving you "hlolo".
So just add a
*str = '\0';
after that while loop.
>>
>>59564048
>Programming in Lua
It's book.
>Any language can be compiled or interpreted
I'd wish to know about Lua being compiled not from philosophical, but from practical standpoint.
>>
>>59563760
>>59564139
Lua has a popular JIT compiler, aptly named LuaJIT.
It's not quite the same as a native executable though.
>>
>>59564139
What are you even saying? A book is the best way to learn a language. Yes, Lua is *typically* interpreted, but any language can be interpreted or compiled
>>
File: tmp_32372-1489537879714940090602.jpg (330KB, 2362x2362px) Image search: [Google]
tmp_32372-1489537879714940090602.jpg
330KB, 2362x2362px
How do I eliminate tail calls?
Example:
(define (factorial n)
(define (iter product counter)
(if (> counter n)
product
(iter (* counter product)
(+ counter 1))))
(iter 1 1))

Let's say, it translate to C this way:
int factorial (int n) {
iter(1, 1, n);
}

int factorial__iter (int product, int counter, int n) {
if (counter > n) {
return product;
}
else {
iter(product*counter, counter+1, n)
}
}

C obvioisly doesn't have TCO, so how do I resolve this problem?
>>
>Stack Overflow in charge of answering questions
>Project due in 3 hours
>Literally have nothing to turn in

JUST

http://stackoverflow.com/questions/43010388/choosing-between-two-fxml-files-when-using-fxml-and-one-controller
>>
>>59564297
I want to learn how people make programs in Lua, not what Lua is.
>>
>>59564425
What are you saying? If you want to learn Lua, read "Programming in Lua". The guy who created Lua wrote the book. If you want to learn to make programs, read SICP.

Are you european or something?
>>
>>59564456
I want to learn how people compound Lua files in their projects.
Is it clear now?
>>
>>59564406
>C obvioisly doesn't have TCO
It's actually an optimisation that a compiler would perform.
But you just need to bring out the arguments to the function as a normal variable, and then use a while loop, with the negated base case as the condition.
int factorial(int n) {
int product = 1, counter = 1;
while (!(counter > n)) {
product = product * counter;
counter = counter + 1;
}

return product;
}


While this could obviously be rewritten to be shorter, I was trying to make it as direct a translation as possible.
>>
>>59564406
Did you even read your SICP?

https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-34.html#%_sec_5.4.2

Fucking slut.
>>
>>59564530
Oh well, gotta get back.
I haven't reached this part yet.
>>
File: Galcon 2.jpg (68KB, 708x400px) Image search: [Google]
Galcon 2.jpg
68KB, 708x400px
I need some help my dudes.

I'm in my second semester, currently in a c++ 2010 class. There's a competition going on next week to write AI for an extremely simplified version of galcon (pic related). I've been assured that I have more enough knowledge to participate, but I don't have the slightest clue how to read from/output to anything outside the compiler other than basic .txt and .dat files.

Am I just fucking retarded? Should I just trust that I'm overthinking this and that it'll make sense when I get there?
>>
>>59564699
>but I don't have the slightest clue how to read from/output to anything outside the compiler other than basic .txt and .dat files.
So, is that somehow a problem?
>>
>>59564734
I'd assume so? The idea is for everyone to pit their AIs against each other and unless I'm completely overlooking something I don't see how we're going to do that without an external program.
The professor running it has explained that it's going to be over a network to ensure people can write in whatever language they feel comfortable, so it's not like we'll just be plugging everything into one compiler.
>>
I want to make something but I don't know what. I'm going to get drunk tonight and program something. What should it be /dpt/?
>>
>>59564784
>The professor running it has explained that it's going to be over a network
Learn game protocol then and work with it.
>>
>>59564792
Something embarrasing that you'll shitpost on /dpt/ and want to kill yourself when you sober up in the morning.
>>
>>59564831
(i've only done this several times)
>>
>>59564828
Is that to say it's something that I'll be able to figure out once i see the game code? Or is there still something I'm missing that I need to figure out before the competition starts?
>>
>>59564530
>This used to be an introductory CS textbook
b-but muh vidya games
>>
>>59563181

There's a lot going on here. I can't speak to the graphics, but in addition to neural networks they're also using genetic algorithms/programming.

Your best bet is to start with the UC Irvine Iris data set and make a NN to identify posies, using Python.

archive.ics/uci.edu/ml/machine-learning-databases/iris/
>>
>>59564884
There's nothing difficult in SICP, although if you skip straight to the last chapter you'll obviously be lost.

Either that or people have gotten more dumb, lazy or whatever. I doubt it though.
>>
File: 1461338670989.jpg (205KB, 506x638px) Image search: [Google]
1461338670989.jpg
205KB, 506x638px
How can I handle errors like ERR_BLOCKED_BY_CLIENT and such in Javascript?

I'm making a simple API call via, but some content blockers stop it executing. I'm after some sort of fallback for this event, but I don't know how to identify it and execute the fallback.

Thanks in advance.
>>
>>59565106
...simple API call to get some JSON,* but...
>>
>>59565106
You don't, the client explicitly stated he doesn't want it. Fuck off with your javascript.

Serve him a flat HTML page.
>>
>>59565106
You get pages and pages of results on googling that error.
>>
>>59565138
How about I make the error an alert telling said user they're a fantastic person?

>>59565143
None of them quite help. Hence why I posted.
>>
>>59565167
>How about I make the error an alert telling said user they're a fantastic person?
Or how about you make the error "can't do this because you disabled javascript, please enable javascript" or whatever.

Is that so hard? Do you need to bypass the client's choice of blocking your crappy website's HTTP request?
>>
>>59565202
>"can't do this because you disabled javascript, please enable javascript"
>...identify it and execute the fallback
That's not too far from what I'm going for.

>Is that so hard?
That's what I was asking
>>
>>59565242
No, it's not. That error isn't coming from javascript being disabled, the "javascript is disabled" was a hint of how to make the error message.

The error is coming from you trying to access a page from javascript with AJAX that has been blocked by the client(according to chrome).

Just error, that's it. No hacks, no nothing, just error.
>>
File: cute_anime_nerd_girl.jpg (124KB, 680x962px) Image search: [Google]
cute_anime_nerd_girl.jpg
124KB, 680x962px
Programming challenge.

You have 7 baskets which you want to arrange with fruit. There are 8 apples (A), 4 pears (P) and 6 oranges (O). Only one type of fruit can exist in a basket at any one time but each fruit can appear in multiple baskets. Can you make it so that, given a random sets of baskets, have fruit configured in this way?
 [ 3A, 0, 2P, 4O, 5A, 2P, 2O ] 
>>
>>59565328
Sure.

# ignore input
print([ 3A, 0, 2P, 4O, 5A, 2P, 2O ])
>>
>>59565328
This is a poorly formed challenge. Be clear about what you actually want.
>>
>>59563898
>>59564117
Thanks, guys.
>>
Is there any point in learning Haskell now that Idris is nearing a 1.0 release?
>>
>>59561930
Good C codes do not exist
>>
>>59565402
The fact that you're using the older meme. Looking down on newfags and such.
>>
Anyone got a discord invite?
>>
>>59565435
Yes

>>>/trash/
>>
Post programming music

https://www.youtube.com/watch?v=hCuMWrfXG4E
>>
In the future, int64_t is going to need to be updated. Will it be called int64_t_t?
>>
>>59565463
https://www.youtube.com/watch?v=asXHYt1Y25s&list=PLiJnN4bTWJ11Qzyj58gC3GY-65ewn-KL3
>>
>>59565483
No, it will be int128_t
>>
>>59565463
https://www.youtube.com/watch?v=Hj0jzepk0WA

I see my code artisan endeavours to be a fight against the current oppressive programming culture. I am training to defeat the mean bullying C programmers. This is my music, this is my life, this is my mission.
>>
>>59565483
int128_t

but really, this won't be necessary until ram reaches 16EB or something to that effect.

If you need 128bit or even 512bit registers, there's already x86 extensions for that.
>>
>>59561751
It's called BOURNEGOL you uncultured swine
>>
>>59563713
>writing a kernel with lambda expressions
>>
Mandatory typed Scheme when?
>>
>>59565495
>FIGHTING HARD NOW
>GETTING HARD NOW
>>
>>59565568
Just use Common Lisp.
>>
>>59565585
There's a reason I'm using Scheme over CL.
>>
>>59565483

There is no need for any fixed width integer type to be updated. There may be a case for int128_t and uint128_t to be implemented on RISC-V 128, but that would not require significant chances to the C standard.
>>
>>59565596
Why?
>>
>>59565601
/dpt/ is always better when you're away. Why are you here?
>>
>>59565602
It's not as much of a clusterfuck.
>>
>>59565601
ruby ruby ruby ruby
>>
>>59565607
But they made a good point though.
>>
>>59565619
Well, I guess you could try Typed Racket then.
>>
>>59565601
Do you use Ruby?
>>
>>59565435
Get in
https://discord.gg/jwwpE
>>
>>59565636
Any retard could have you told you that a fixed width integer would remain fixed width.

Don't bother with it. Try to ignore it.
>>
File: stitch.jpg (743KB, 1920x1896px) Image search: [Google]
stitch.jpg
743KB, 1920x1896px
I'm just learning OpenGL.

I just spend 30 minutes wondering why translating my view matrix by (1i, 0j, 0k) was moving everything to the right instead of to the left, like you'd expect from a camera moving to the right.

Turns out I completely missed the point that I'm working with matrices and vectors, not with a real world camera, and that multiplying my other matrices by the translated view matrix means I'm just translating everything else as well. In my head, what I knew of Linear Algebra just didn't seem to be there for this sort of stuff.

It feels like such a paradigm shift.
>>
>>59565679
it will NEVER be intuitive
>>
>>59565714
Neither will life but these are the things we must deal with.
>>
>>59565714
It is. Do you expect the code to magically move around your monitor in real life? You have to move around what it's displaying so that your monitor can see it.
>>
>>59562008
Hipp looks like Steve jobs.
>>
>>59565679
>OpenGL
Too late, learn Vulkan.
>>
>>59562924
everything. Just put all your code in header files
>>
>>59561930
DOOM
>>
>>59565787
thank, very good compile time. no strang compile code lincing. thank from india.
>>
>>59565740
Baby steps. Once I get good enough at OpenGL, which already has good support, I'll tackle Vulkan.
>>
>>59565435
>>59565660
Fuck off back to >>>/v/
>>
>>59565463
Listening to this right now.

https://www.youtube.com/watch?v=odBDjYK1gz4
>>
>>59565663
Except there were people already posting in this thread who apparently couldn't grasp the point. Ruby was stating the bleeding obvious, but compared to the kind of people who think "int64_t_t" makes sense, that makes them basically genius tier.
>>
>>59565855
Cry more faggot
>>
>>59565607
I have been neglecting you all. I need to remedy that.

>>59565644
Yes.
>>
>>59565897
These are the same people who have never used stdint.h and shitpost javascript or rust every 2 seconds.

This kind of retardation predates ruby's pathetic attempts at C on /dpt/.
>>
Why did nobody tell me Rust was this nice?
>>
>>59565942
A shame it can only do trivial cross-compiling
>>
>>59561930
musl, glibc, mpv, vlc, mesa, mupdf.
>>
>>59565944
That's a good point, but then at this stage I'm only dealing with linux anyway so w/e
>>
>>59565949
>glibc
The interface is C +++++++++++++(no relation to C++), but the actual code base is not by any means good.
>>
>>59565463
https://www.youtube.com/watch?v=Nco7qfrPG7I
>>
>>59565983
works bad only with encodings.
>>
>>59565983
It's kind of pathetic that modern ISO and POSIX basically just take GNU C and make it standard one piece at a time.
>>
>>59565923
Do you use Crystal?
>>
File: 1472362242684.jpg (21KB, 221x246px) Image search: [Google]
1472362242684.jpg
21KB, 221x246px
>>59561050
How do i bundle a unix executable into an iOS app?
>>
>>59566034
That's not glibc though. glibc is good but has "GNU-isms", which are great but none(very few) of them go into standards.

gcc-isms is a different story, it's not glibc but is the compiler that everybody uses.
>>
>>59566034
There is only two C libraries musl - which don't want to implement glibc features for performance, but make code simple.
glibc which don't want to update.
>>
>>59566077
You forgot bsd libc.
>>
>>59566104
and uclibc, dietlibc.
>>
>>59564117
I actually had the time to look over this again, and make the fixes, and this made a lot of sense. Thanks again for the detailed explanation.
>>
>>59566119
I meant things that are somewhat relevant. BSD takes precedence over musl a million times over.
>>
>>59561616
>Haskell programming from first principles

Always read "Learn You A Haskell" when beginning to learn Haskell. The author is an explanation genius.
>>
>>59566119
and Bionic
>>
>>59566167
Literally who?
>>
>>59566166
Have to say I disagree.
>>
>>59566176
bionic - small standard c library from Google, based on BSD libc.
>>
how do I git gud at visual studio?
>>
>>59566241
Killing yourself or killing all others in order to make your shit the top dog.

Choose one.
>>
>>59566259
it's just an editor man, chill
>>
>>59566241
emacs
macs
acs
cs
s
>>
>>59566269
It's not just an editor, and use of it borders on insanity.

Trust me, the last guy I killed said I was perfectly sane.
>>
>>59566292
Why use emacs when vim exists?
>>
>>59566036
Nope!

>>59566241
Use something else.
>>
>>59566331
Any reason why not?
>>
>>59566331
>Use something else.

On windows? no
>>
>>59566331
Any reason why you used your tripcode for 2 shitpost responses?
>>
>>59566241
enable virtual spaces
>>
>>59566331
>>59566340
>>59566351
>>59566356
Fuck off furfag and stop shitposting.
>>
>>59566381
Not all minerals are made alike, just like all tripfags. It's a failed trap pony fag.

He's been posting here for quite a while, ~2 years after the initial /dpt/ image wars.
>>
>>59566423

tripfags are shit
>>
>>59566437
C# sucks
>>
>>59566437
You're just a shitposter who uses a tripcode, different category. You don't even qualify as a tripfag.
>>
>>59566340
Because Visual Studio is bloated garbage. I only use it when forced. Willfully using it seems silly.

>>59566356
Because I can.

>>59566370
No.
>>
>>59566458

That's not fair. I've posted useful things before.
>>
>>59566498
Whatever anon you helped, it becomes irrelevant when you shitpost across 12 boards about how your love fat nigger women.
>>
>>59566494
I meant why you don't use Crystal.
>>
File: thinkinman.jpg (79KB, 1024x576px) Image search: [Google]
thinkinman.jpg
79KB, 1024x576px
I am currently learning C, so far, so good. My problem is that when it comes to programming challenges I completely freeze up, and don't know what to do. I understand what I have to do, but don't really know how to "translate" my thoughts into code. Will a good algorithms book solve this problem? How do I stop being retarded?
>>
>>59566494
>Because Visual Studio is bloated garbage. I only use it when forced. Willfully using it seems silly.

as opposed to what?
>>
>>59566524
vim
>>
>>59565983
>The interface is C +++++++++++++(no relation to C++)
Clarification is requested.
>>
>>59566515

Fat black women need love, too. :)
>>
>>59566538
on windows? no
>>
File: do not.jpg (7KB, 262x192px) Image search: [Google]
do not.jpg
7KB, 262x192px
a-hem
>>
>>59566553
http://www.vim.org/download.php#pc
>>
>>59566553
It doesn't take 6 hours to install vim on Windows.
>>
>>59566594
vim is fine on linux, it fits in with the ecosystem very well. However, the vim workflow pretty much doesn't exist on windows
>>
>>59566517
Learn Lisp.
>>
next: >>59566658
>>
>>59566524

Sublime Text for editing.
GCC or Clang for compiling.
Thread posts: 315
Thread images: 23


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.