[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: 345
Thread images: 36

File: haskell.png (12KB, 225x321px) Image search: [Google]
haskell.png
12KB, 225x321px
What are you working on, /g/?

Previous thread: >>61898971
>>
File: android-sdk.jpg (21KB, 300x280px) Image search: [Google]
android-sdk.jpg
21KB, 300x280px
Thoughts on Android development from a technical standpoint? Is it more powerful / better than iOS?
>>
>>61905907
Install Pelles C.
>>
File: hime c.png (1MB, 1280x720px) Image search: [Google]
hime c.png
1MB, 1280x720px
Explain why you aren't compiling your C projects with -std=c89 -pedantic-errors

Non-standard compiler extensions are a crutch and lead to non-portable codebases.
>>
>>61905956
Because I like to do more with my code than math and have pointers referencing pointers referencing pointers
>>
>>61905956
Because C89 is dire.
>>
does flashing a graphics card for OSX use count?

its an absolute bitch and worried about bricking my precious
>>
>>61906044
flashing a GPU happens at the firmware level, so the OS shouldnt matter unless you're doing something whacky
>>
>>61905956

I compile with -std=c11 -pedantic-errors

I have no reason to limit myself to outdated versions of the ISO C standard when every compiler worth using supports ISO C11.
>>
>>61906133
>c11
>not gnu11
Way to stay irrelevant gramps
>>
>>61905927
trying to get a java program to connect to fucking google sheets so that I can read data sent to a spreadsheet there by a couple text fields on squarespace
>>
>>61906164

Technically a compiler extension, and not a C standard. Doesn't work on the Small Device C Compiler, which is used for certain embedded devices.
>>
>>61906064
most cards natively work on OSX. but only mac edition cards can display the bootscreen, because theyve been flashed with a special EFI. the problem is that most models dont have a mac edition and even when they do, theyre expensive as hell

so now i have to modify an older apple approved EFI to essentially piggyback on the card's BIOS and hope it works.
>>
>>61906201
On embedded you are not going to be using C11 anyways to might as well use gcc extensions, unless you want to embed something like tcc into your program in which case you should limit yourself only to those gcc extensions which tcc supports.
>>
Aside from being able to mix declarations and code, what are some C compiler extensions that are actually worth using?
>>
>>61906226

No reason not to use C11 on embedded.
>>
>>61906255
({ })
typeof
never used but clang supports closures for C.
>>
Working on my x86_64
        .global _start
.text
_start:
xor %rax, %rax
push %ax
mov $0x68732f2f6e69622f, %rbx
push %rbx
mov %rsp, %rdi
push %rax
push %rdi
mov $59, %al
mov %rsp, %rsi
xor %rdx, %rdx
syscall
.byte 0
>>
https://github.com/UlfNorell/x86-agda
>>
>>61906255
C++
>>
>>61906284
Other than no compiler supports it
>>
>>61906296
CISC is deprecated, anon.
>>
>>61906311
Pelles C supports C11.
>>
>>61906255

>Mix declarations and code
Pretty sure that's valid C already, so long as you're using at least C99.

>>61906311

Small Device C Compiler. Supports everything relevant not supported by GCC or Clang.
>>
>>61906324
but it doesn't support any platform that GCC doesn't support.
Only when you go to uncommon platforms where you can't use gcc you also can't use C11
>>
>>61906318
Tell me more.
>>
>>61905937
It's a good example of what enterprise level OOP code should look like. But you see now that pajeets are running the show the API fell in quality.
>>
>>61906338
No, I've told you enough.
>>
>>61906296
>AT&T syntax
TL;DR
>>
>>61906318

x86_64 is not deprecated; it has no valid replacements.
>>
>>61906358
It's a detail.
>>
>>61906400
%it's %a %detail
>>
>>61906409
Of course.
>>
>>61905956
I am, actually. I don't like how C11 redefined the abstract machine. The threads support is crap.
>>
File: old_hag_langs.png (173KB, 600x355px) Image search: [Google]
old_hag_langs.png
173KB, 600x355px
Still waiting.
>>
>>61906296
It's been a while, I'm rusty. What syscall is this? Linux has no syscall 0
>>
>>61906842
FOrget about the .byte 0, it's useless.
Syscall is what replace int $0x80. You can still do int $0x80, but it works only with 32bits addresses.
>>
>>61906867
I know. What I don't get is where you're pulling your system call number from. Involving rax I only see a xor and some stack management. IIRC xor X, X zeroes the register, and system call numbers start at 1. I don't know why you pushed rax to stack, but I didn't examine it too closely. Unless some instructions put a value in rax (I dont remember really) I dunno what you did.

I just made a generic system_call(arity, number, ...) function with inline assembly and called it a day
>>
>>61906990
xor %rax, %rax
rax is 0
mov $50, %al
rax is 59
so when the pc reach syscall rax is 59
>>
>>61907011
al sets rax? Man I don't really remember lol. also looks like I was wrong about them starting at 1 too, read is 0... Anyway, 59 is execve

So I guess that constant holds interesting data
>>
>>61906296
So, you pushed a constant to stack, then moved the constant at stack pointer to rdi, where the pointer to the filename is supposed to be?

Wtf does it point to?
>>
>>61907106
32 lower bits of rax are eax
16 lower bits of eax are ax
8 higher bits of ax are ah
8 lower bits of ax are al
so setting al to 59, set the whole rax to 59

the syscalls were renumbered from 32bits to 64bits.

>So I guess that constant holds interesting data
There is no zero in the generated code (except the trailing byte 0, that is useless).

>>61907151
>Wtf does it point to?
Just follow the code anon.
>>
>>61907151
No wait, that's wrong. You pushed the constant to stack, then moved its address, the stack pointer, to rdi. Nice.

Brb while I decode that shit
>>
>>61907171
>
hs//nib/


Wot
>>
>>61907465
You read it in the wrong order anon.
>>
>>61907481
>
/bin//sh


Cool, a valid path
Is this because of little endian bullshit of Intel
>>
>>61907519
Going from lower to higher, is the best order. So Intel is right.
>>
>>61907538
Aight.

execve(char * filename = "/bin//sh", *argv = ?, *envp = 0)


I see you also move stack ppinter to rsi. Hmm...
>>
>>61907607
You need rsi to have a decent shell, otherwise starnge things happen
>>
>>61907632
>mov rsp, rsi
>rdi was last pushed to stack
>rdi contains pointer to filename

execve(char * filename = "/bin//sh", *argv = ["bin//sh"], *envp = 0);


???
>>
>>61907705
Yes. But to be precise, after the pointer to filename there is a null pointer (push %rax), argv has length 2.
>>
File: 1502554078961.png (111KB, 600x800px) Image search: [Google]
1502554078961.png
111KB, 600x800px
Reminder
>>
>>61907738
Oh yes, you're right about that.

But where is filename's NULL --

>push ax

oh...


execve(char * filename = "/bin//sh", *argv = ["/bin//sh", 0], *envp = 0);


So yeah I guess that explains the stack usage. I guess that repeated filename shit is for argv[0], I'd totally forgotten argv[0] is the "program invocation" thingy. IIRC bash will work in POSIX mode if it's called as sh
>>
>>61907767
How am I supposed to do low level development using only functional programming languages?
>>
>>61907823
You got everything right now. But you miss the main points:
it has no zero bytes when "compiled"
it's just 30 bytes long

But today it's just an useless toy.
>>
>>61907828
It's a joke. It's certainly not practical to only know and use those three.
>>
>>61907767
what if you want to do anything lower level than "code artisan"?
>>
>>61907828
>what is pre-scheme
>>
>>61907828
You're not supposed to do any development using only functional programming languages. It's a meme. Pretty much like feminine penis.
>>
What did you learn today /dpt/?
>>
>>61907873
bunch of vocabulary words for the GRE
>>
>>61907828
ASM monad
>>
>>61907767
Does anyone actually use Shen? I watched the video on their web site, and it looked like some post grad just duct taped LISP and prolog together and tried to sell it to people.
>>
>>61907828

If you have access to mmap (there's no reason you shouldn't have) you can just map in an executable page and emit instructions into it, and then FFI jump into it

>>61907845
Cool. Nice memory refresher...

I know the joy of tiny programs, I'm working on a C project without any libc crap right now... I did write that system_call function for it. It's not as small as an assembly file, but it's got no glibc faggotry
>>
File: Screenshot_20170815-010013~01.png (487KB, 829x836px) Image search: [Google]
Screenshot_20170815-010013~01.png
487KB, 829x836px
>>61907873
How easy hotswapping code is in C.
I don't like it. C shouldn't be the best language.
>>
>>61907886
how are you supposed to use that effectively without knowing assembly?
>>
>>61907911
>I know the joy of tiny programs
No you don't get it. It's a shell code, something made to be injected in an unchecked strcpy (no 0 byte).
>>
>>61907936
Look at the types
>>
>>61907936
Write a neural network that learns to translate haskell to asm. Make an interface to the asm monad that invokes the NN to translate your haskell code to asm.
>>
>>61907873
How to run lldb with xcrun so I don't have to use fucking xcode anymore.

lldb is awesome.
>>
>>61907989
that's too easy
>>
>>61907959
Huh... I always preferred to use mem* functions because of shit like this. Never trusted the fucking null terminators

I suppose you'll do some stack exploit to get it to return into the beginning of that code, but I'm not sure what good spawning a shell does. It will kill the process so I guess it denies service at the very least, unless you got some shell script to feed into it somehow
>>
>>61908044
forgot my image.

Having a poke around the Health app on iOS
>>
>>61908097
Just a toy. In the past those kind of things were used to exploit setuid programs and became root. But now a lot of things are made to prevent that (stack is no more executable).
>>
File: 1500982329768.jpg (2MB, 3840x2160px) Image search: [Google]
1500982329768.jpg
2MB, 3840x2160px
>>61908128
i love seeing screenshots of code.

you can actually see people working on
>>
Is there a desktop (X11) based implementation of the Android APIs,
so I can run my Android app without an emulator?
>>
just finished my final for gis programming

import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace= arcpy.GetParameterAsText(0)
#input
inputFC = arcpy.GetParameterAsText(1)
#output
outputFC = arcpy.GetParameterAsText(2)
#distance
distance = arcpy.GetParameterAsText(3)
#split
split = arcpy.GetParameterAsText(4)
#side type
sidetype = arcpy.GetParameterAsText(5)
#end type
endtype = arcpy.GetParameterAsText(6)
#method
method = arcpy.GetParameterAsText(7)
#dissolvetype
dissolvetype = arcpy.GetParameterAsText(8)
#dissolve field
dissolvefield = arcpy.GetParameterAsText(9)

arcpy.AddMessage("Counting Features...")
workspace = arcpy.env.workspace
split = int(split)
inscal = arcpy.GetCount_management(inputFC)
inscal = int(inscal.getOutput(0))
arcpy.AddMessage("Features Counted!")
counter1=1
counter2=((inscal/split)+1)
arcpy.AddMessage("Creating Scratch Folder...")
arcpy.CreateFolder_management(workspace, "distbuff_temp")
arcpy.env.workspace = workspace+ "\\" + "distbuff_temp"
arcpy.AddMessage("Folder Created!")

arcpy.AddMessage("Cracking Features...")
while counter1 <= counter2:
arcpy.Select_analysis(inputFC,"distbuff"+str(counter1),'"FID">=({0}*({1}-1)) AND "FID"<({0}*{1})'.format(split,counter1))
arcpy.AddMessage("Splitting... {0} \\ {1}".format(counter1,counter2))
counter1+=1
arcpy.AddMessage("Features Cracked!")
FClist = arcpy.ListFeatureClasses()
arcpy.AddMessage("Buffering Cracked Features")
for FC in FClist:
out = str(FC)
arcpy.Buffer_analysis(FC,"out"+out[:-4],distance,sidetype,endtype,dissolvetype,dissolvefield,method)
arcpy.Delete_management(FC)
arcpy.AddMessage("Buffering {0}".format(FC))
arcpy.AddMessage("Buffering Complete!")
arcpy.AddMessage("Merging Features...")
FClist = arcpy.ListFeatureClasses()
arcpy.Merge_management(FClist,outputFC)
arcpy.AddMessage("Merging Complete!")
arcpy.AddMessage("Cleaning Up!")
arcpy.Delete_management(workspace+ "\\" + "distbuff_temp")
arcpy.AddMessage("Cleaned Up!")
>>
>>61908162
a prepaid throwaway android device costs no more than $20 at any store
even a cheap and shitty lollipop phone works better than an emulator
>>
how do you say code at loud?
pronounce foo();, int x = 1;, and foo(bar);
>>
>>61905624
>>61905637
>>61905712

Thanks for that guys, but I wasn't looking for the structure of a C Project. I was looking for the structure of your over arching coding directory.

I was looking for where you store C code/projects, other languages, etc. For example something like this

development
->C
-->Projects
-->Stand alone files
->Bash
-->Projects
-->Scripts
->Other Languages
->Etc


I don't know what to classify everything as, and I'd like to have it rather clean
>>
I've been thinking about making a genetic algorithm to dither black and white images just to see if I can get close or better results than classic error diffusion algos like floyd-steinberg.
>>
>>61908157
That is a debugger showing machine code for an application, not really code.

But since you like seeing code here is some I wrote today as a rough first draft for sorting addresses grouped by streetname, then ordered by house address. :)
>>
>>61908210
foo paren

int ecks equals wun

foo paren bar
>>
>>61908215
I dont usually organize by language. The language is just a tool for implementing the idea, rarely defines the idea, so IMO it doesnt help with organization. Nevertheless I have a Rust and Haskell folder but thats because I have lots of scratch files for playing with language features. My real projects are all in ~/Projects
>>
>>61908210
>call foo
>int ex equals one
>call foo with bar
>>
>>61908234
nice!

why not emulate the app on a physical iPhone?

isn't it faster? at least on Android
>>
>>61908234
what is this font senpai
>>
>>61908240
>>61908282
what about if(x == (y + (5 - foo(bar)) / 2)))
>>
>>61908215
>~/src/project/name
my stuff

>~/src/repo
repos I pulled because I wanted to read

>~/src/snip
Quick things I wrote that I may want to reference later.

>~/src/etc
other, disorganized chaotic directory
>>
>>61908323
if x is equivalent to y plus 5 - foo of bar over 2
doesn't matter if it's ambiguous because code being discussed will almost always be written down somewhere nearby
>>
>>61908234
i didn't understand the part you said you didn't need xCode anymore.

don't you need it yo make iPhone apps?

and why are interested in
>machine code for an application
?
>>
#include <stdio.h>

int
main ()
{
int qmark_code;
qmark_code = (int) '?';
printf ("Code for ? = %d\n", qmark_code);
}

Why do I get " Code for ? = 63 " as output? Where did 63 come from?
Also if I
double qmark_code;
output is " Code for ? = 1175288312 "
>>
>>61908252
I'm more thinking along the lines of organizing coding snippets for each language. I have a bunch of scratch files for a bunch of languages and its really unorganized

>>61908324
A scratch/snippet folder is what I was missing! Hopefully that'll make things a bit neater
>>
>>61908387
the ascii symbol '?' is represented as the integer 63.
You interpreted an ascii character as an integer.
>>
>>61908387
You're converting the question mark to its ASCII code, which is 63.
>>
>>61908323
>if x equals y plus 5 minus call foo with bar over two

If they want the details they can read the code
>>
>>61907828
How low-level? There are HDLs that are based on FP langs. The core concepts map well.
>>
so how do i find a string in an array and actually just print out the match, the contains() procedure only returns a true/false value

java btw
>>
>>61908501
I could fashion together a function that repeatedly uses the contains() procedure with a string offset until the string is found, but i'm sure you wouldn't know how to wrap your head around that.
You also don't know the first thing about writing a naive substring searching function.
>>
>>61908501
If you already have the value of the element you're searching for in the array, why would you need the procedure to give it back to you?
>>
using pthreads how can I limit the number of threads while smoothly destroying finished and creating new threads

to limit to 10 threads I had it check for if the thread count rose above 10, and then wait for all threads to join

but that is really slow and waits for all threads when I really just need to wait for ANY thread to finish

any ideas?
sounds like a thread pool. but I dont want to use BOOST
>>
>>61908558
Just write a goddamn thread pool.
It's piss easy and if you can't write something this elementary and simple, you have no business writing mulithreaded code of any kind.
>>
>>61908558
even limiting to 100 threads, processing ~250 images takes 7 times longer with this method

>>61908572
fine
>>
>>61905927

Anyone got book recommendations that will improve coding without being pure language books? I've done SICP and halfway throw GEB.
>>
>>61908824
Sometimes I read the EWD manuscripts..

http://www.cs.utexas.edu/users/EWD/
>>
>>61905927
>working on problem
>having extreme difficulty, can't get it working, give up
>come back a few months later
>absolutely 0 problems, can't believe how much I was over-complicating things

I love the early stages of learning a new skill because you see so much improvement in such a short amount of time. How
>>
>>61909272
what problem?
>>
>>61908175
Never molest a keyboard again jfc
>>
>>61909298
I don't even want to say because it's so simple.
[spoiler]Caesar Cypher in C[/spoiler].

In my defense, I wasn't very experienced with C, or any language, at all. I wasn't far off, it's just my solution back then was extremely over complex and unwieldy and it didn't work with numbers over 26.
>>
File: index.jpg (6KB, 262x193px) Image search: [Google]
index.jpg
6KB, 262x193px
>>61909345
>>
>>61905956
Explain why you are using a c standard. c was much better before c89
>>
>>61909390
I figured it out. There was a primary key missing in the referenced table. No idea why that would throw an error.
Maybe ginger can put down that gun and tell me...? Please?
>>
>>61909335
your spoiler didn't work i can read the spoiler

go back to /g/rules
>>
File: Vqr4p1E.png (116KB, 1515x663px) Image search: [Google]
Vqr4p1E.png
116KB, 1515x663px
>Re-posting because got no answer in the other thread.

>Sign up for the BS program in Comp Sci
>Somehow got automatically set in the system as a BA in Comp sci

I heard having a BS (because of the additional math) makes you a better candidate for jobs over a BA, how true is this? Anyone wanna share their own experience post college?

I'm a transfer student with no internships and I'm already worried enough about finding work post-grad.
>>
>>61908175
>arcpy.CreateFolder_management
>arcpy.AddMessage
>FClist

>overwriteOutput
>sidetype


holy shit anon choose a formatting style and stick with it
>>
>>61909562
>consistency in code
enjoy being easy to replace with a robot or another, younger worker who will accept lower wages.
>>
File: ffdasfasdfffd.jpg (35KB, 305x267px) Image search: [Google]
ffdasfasdfffd.jpg
35KB, 305x267px
>>61909595
yes anon, I always make sure I have inconsistent naming conventions in my code so I won't be replaced with a younger worker. (????)
>>
>>61909595
The trick isnt to use bad naming conventions, its to use obscure languages like Shen, Agda or Io.
>>
>>61909595
enjoy wasting your time screwing around with totally unmaintainable code.
>>
I'm in between internships right now, and I was wondering what kind of decent paying part time programming work is out there. I have another job that pays ~20$ an hour, do you think there's anything comparable?
>>
Fuck reading papers. I'm sick of damn pseudocode.
>>
>>61908548
Sounds like anon wants someone to do their homework for them
>>
why the FUCK do people like python?

yeah sure there's a big community with lots of libraries but why did there even become a community in the first place when the language is such a piece of shit

>totally untyped/dynamically typed arithmetic
>yet the / operator works totally differently if one of arguments happens to be an integer
>/ works totally differently in versions 2 and 3
>integer division floors rather than truncates towards 0

why would anyone use a dynamically typed language anyway?
it's just "hey dude would you like an extra layer of possible, annoying to find bugs for no reason?"
"Oh boy yes please this will make me so much more productive"

what absolute garbage.
>>
>>61909890
>what absolute garbage.
go ahead and make a better one
>>
I'm trying to make a loop that counts all the numbers between 1 and 1000.
>>
>>61910021
sum(range(1,1000))
>>
>>61910021
just sum them by hand and put the result in the code
>>
File: images.jpg (8KB, 289x174px) Image search: [Google]
images.jpg
8KB, 289x174px
>using rust for web dev

https://thefullsnack.com/en/rust-for-the-web.html
>>
>>61910041
in haskell this is just
(foldl (+) 0 . (enumFromTo <*> (999 +))) 1
>>
>>61910041
>O(n) solution to a O(1) problem
Good job.
>>
>>61909913
people already have. Java is a better language.

The only thing python has going for it are it's libraries that people kindly decided to make for it.

the language itself is aids.
>>
>>61910021
>trying
What language? This shouldn't be hard.
>>
>>61910132
here you go snowflake
fuckyou = lambda n: int(n*(n+1)/2)
>>
>>61910136
>the language itself is aids.
i find it very simple.

maybe you have a problem
>>
>>61909890
No clue, but I fell for the "Python for beginners" meme and it almost completely put me off programming entirely. I didn't like it at all. Thankfully I eventually listened to an anon on this board and tried C instead, instantly things began to click and I began to enjoy it. I might have a better appreciation for python (or not) now that I'm slightly more experienced, but for a first language I found it awful.
>>
>>61910021
   return (n * (n + 1)) / 2
>>
>>61910196
sumTo = (`div` 2) <<< (*) <*> succ
>>
>>61908824
Is Scheme even worth using?
>>
>>61910132
>a loop that COUNTS
>>
>>61910436
Scheme becomes worth it when you're willing to write macros. Without that, it's just kind of a simple language with a few decent data types etc, but small compared to most others.
>>
>>61910436
SICP doesn't really teach scheme, just teaches the minimum to proceed. But yes LISP languages are great imo.
>>
>>61910450
Your point?
>>
>>61910473
>a LOOP
>>
>>61910454
What about Common Lisp?
>>
>>61910190
>I find bad features simple
Impressive. Well done lashing out rather than refuting any of the criticisms made.
>>
>>61909562
>that list
only sidetype and FClist are mine and FC is capitalized throughout the entire program. my consistency is fine

>inputFC
>outputFC
>FClist
>>
>>61910505
A lot of people like CL a lot, I don't use it nearly as much as Scheme. It has a lot of external libraries, and a big standard lib, but the standard lib is confusing and I don't like the documentation.
>>
>>61910481
Are you autistic?
Stop being autistic.
>>
>>61910541
lmao what are you talking about, stanard lib is great
streams are goat, can you even make strings streams in your little scheme
>>
>>61910561
open-input-string
>>
>>61910552
Your solution isn't a loop, moran!
>>
>>61910021
for x in range(2,1000)
print "OP has sucked {0} cocks".format(x)


what do you mean by counts tho
>>
>>61910575
>Python
Hi. I hate you. Die!
>>
>>61910574
None of the solutions posted are since there are 0 (zero) valid reasons to use a loop for this.
>>
>>61910587
don't mind me i just like having an easy to read language to extend my skills as a GIS analyst

python works for me, if it doesn't work for you that's totally fine.

as long as you don't use R
>>
>>61910593
There's 0 (zero) reasons to sum numbers from 1 to n outside of stupid programming exercises
>>
>>61910613
>sum
>>
Why are so many people afraid of powerful static type systems?
>>
>>61910613
Tell that to J.G. Büttner.
>>
>>61910665
877 cash now!
>>
>>61910541
What can you even do with macros?
The only use I've had so far is compartmentalization but with still being able to access local function data. (as if by (declare (special variable)) (but the loop macro won't let me #'declare))
>>
>>61910505
CL is huge and can be overwhelming. However, SLIME is probably the single best development tool I've ever used for any language.
>>
>>61910734
But you have to learn emacs, danm.
Wish there was for vim.
>>
>>61910686
Basically you just use macros to make your life easier and your code easier to read.
Declaring a lot of structs the same way? Use a macro.
Creating a table of relations that has some ugly complicated internal representation? Use macros to make it more clear.

Usually when programming you use functions to abstract behavior to make it easier to understand, or to avoid repeating yourself, or to be more reuseable. Use macros in the same way whenever functions wouldn't do the job.

I'm currently writing a routine that converts abstract syntax trees into a variant with more information. I'm going to reform it to use macros so that it'll be a lot less repetitive.
>>
>>61910686
This article really convinced me of the power of macros.
http://stevelosh.com/blog/2016/12/chip8-cpu/

Like holy shit this is *code*, not documentation:
(macro-map                                              ;; SE/SNE
((NAME TEST X-ARG X-FORM Y-ARG Y-FORM)
((op-se-reg-imm = (r 1) (register r) (immediate 2) immediate)
(op-sne-reg-imm not= (r 1) (register r) (immediate 2) immediate)
(op-se-reg-reg = (rx 1) (register rx) (ry 1) (register ry))
(op-sne-reg-reg not= (rx 1) (register rx) (ry 1) (register ry))))
`(define-instruction ,name (_ ,x-arg ,y-arg)
(when (,test ,x-form ,y-form)
(incf program-counter 2))))
>>
>>61910021
int count = 0;
for(int n = 1; n <= 1000; ++n) {
++count;
}
>>
>>61910776
>a routine that converts abstract syntax tree
isn't that literally a macro though
>>
>>61910574
>>61910481
>>61910450

int r = (n * (n + 1)) / 2;

for (int i = 0; i < n; i++)
r = r + 0;

return r;
>>
>>61910893
I'm writing a compiler; it's an AST of protobuf code
>>
File: chen_face.png (68KB, 289x398px) Image search: [Google]
chen_face.png
68KB, 289x398px
>>61910021
n*(n+1)/2
>>
>>61906186
Python for simple job my man. Java for server side
>>
File: cheeeen.gif (401KB, 500x375px) Image search: [Google]
cheeeen.gif
401KB, 500x375px
>>61910919
>>
convince me to work one of the dozens of projects I've abandoned due to extreme apathy/incompetence
>>
>>61908210
Foo
Int X equal one
Foo of bar
>>
How do I get the world-space bounding box of a box?
I can do it, but my code is getting messy.
I have a vector math library at my disposal.
>>
File: chen_roomba.webm (534KB, 1000x700px) Image search: [Google]
chen_roomba.webm
534KB, 1000x700px
>>61911044
Damn that's really cute.
>>
>>61911223
Just apply the transformation in inverse
>>
>>61910131
sum [1 .. 1000]
>>
>>61911444
(If it's right-inclusive)
>>
>>61905956
animu?
>>
>>61910021
>>61910041
>>61910196
>>61910919
/g/tards don't know the difference between counting and summing. pathetic
>>
>>61910131
foldl' (+) [1..1000]
>>
whats a header file for? is it possible to code a working software with it?
>>
what did drracket mean by this?
>>
File: 1408819542770.png (19KB, 130x130px) Image search: [Google]
1408819542770.png
19KB, 130x130px
#ifndef HEADER_GUARD__CUBE_MODEL
#define HEADER_GUARD__CUBE_MODEL
#include "../../common/shared.h"

extern struct model_data cube_model; // = (struct model_data *) malloc(sizeof(struct model_data));
cube_model.vertex_xyz = {
....
#endif

###
$ make
g++ -Wall -c mainloop.cpp
In file included from mainloop.cpp:12:0:
assets/raw/cube.h:6:1: error: ‘cube_model’ does not name a type
cube_model.vertex_xyz = {
^~~~~~~~~~
assets/raw/cube.h:45:1: error: ‘cube_model’ does not name a type
cube_model.vertex_RGB = {
^~~~~~~~~~
assets/raw/cube.h:84:1: error: ‘cube_model’ does not name a type
cube_model.vertex_uv = {
^~~~~~~~~~
make: *** [Makefile:14: mainloop.o] Error 1


why though
>>
>>61911773
abs is already defined by r5rs. call it my-abs or somethign
>>
>>61911812
but I want it to be defined, it isn't recognizing abs

>This chapter describes Scheme's built-in procedures. The initial (or "top level") Scheme environment starts out with a number of variables bound to locations containing useful values, most of which are primitive procedures that manipulate data. For example, the variable abs is bound to (a location initially containing) a procedure of one argument that computes the absolute value of a number, and the variable + is bound to a procedure that computes sums.
>>
>>61911840
abs is definitely already defined. You can't redefine it because it's already defined.
>>
>>61911805
You can't initialize values in the top level. Use a function.
>>
>>61911869
I see. Thanks.
>>
>>61911805
>>61911805
You cant just slap code in a header file, it has no scope. You need to modify cube_model in a function or something.

You can (I think) pre-init the extern struct like this:

extern struct model_data cube_model = { .vertex_xyz = blah, .vertex_RGB = blah, etc };
>>
>>61911867
was it not defined when sicp was written? because they use abs the exact way that's giving me the error (it does work when I rename abs)
>>
File: casey was able to compile this.png (45KB, 1418x473px) Image search: [Google]
casey was able to compile this.png
45KB, 1418x473px
i have
 typedef internal static
in win32_handmade.cpp but it wont work?

im just following casey (handmade tutorial) here
>>
>>61911924
>using Meme Studio
>>
just replace internal with static. Don't fuck up C++ anymore than its already fucked up.
>>
>>61911936
>>61911924
That was for you
>>
>>61911935

are there other IDE that can debug the registry/memory?
>>
>>61911923
SICP probably doesn't use R5RS.
DrRacket has a SICP language, and you can redfine abs in it.
https://docs.racket-lang.org/sicp-manual/
>>
>>61911946
The fuck is registry memory?
>>
>>61911946
>using a debugger
>not just fixing issues through printf or not coding bugs at all
>>
>>61905956
Plenty of stuff critical for making portable code was introduced in C99.
>>
>>61911923
m8, you do realize scheme was made as a very small language by MIT for teaching purposes
the various standardizations and SRFI extensions came much later
scheme as SICP uses it is a very different lang than RNRS
>>
>>61910122
>rust
>on web
Why
>>
>>61912351
/g/ told me to read sicp and I googled for the best scheme interpreter
I don't know much about anything
>>
>>61912383
learn scheme through 'The little schemer'
SICP is too hard to tackle for most without a solid grounding in at least basic scheme
>>
>>61912373

Gotta go fast.

If we could get all of those Electron babies to switch to Rust, that might at least be nice.
>>
>>61908175
What the shit is this?
>>
>>61908387
>type cast a character into an int
>get ASCII number for '?'
>>
>>61912408
Rust will never become fast or useful.
>>
>>61910575
Kek'd.
Python worst girl.
>>
>>61912400
I picked sicp since I'm watching the lectures as I go

https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/video-lectures/
>>
File: 9156672821.jpg (88KB, 1032x720px) Image search: [Google]
9156672821.jpg
88KB, 1032x720px
#pragma once


Use it
>>
>>61912449

>never become fast
It has the potential to be as fast as C++ once the compiler becomes more refined. As for useful... only time can tell It just needs libraries and stability.

>>61912547

Not valid ISO C11.
>>
>>61908316
Inconsolata

http://levien.com/type/myfonts/inconsolata.html
>>
Hey guys, I haven't touched C in a while can someone help me understand this:

void reverse(char *str) {
char * end = str;
char tmp;
if (str) {
while (*end) {
++end;
}
‐‐end;
while (str < end) {
tmp = *str;
*str++ = *end;
*end‐‐ = tmp;
}
}
}


particularly what is happening/what it means to increment a string and use it as an if condition.

What the code is meant to be doing is just reverse a string.
>>
File: reverse-code.jpg (41KB, 599x599px) Image search: [Google]
reverse-code.jpg
41KB, 599x599px
>>61912713
sorry fucked up the formatting, here's a pic
>>
>>61908350
you have some command line tools like:

xcrun
xcodebuild
lldb

That allow you to do everything that you typically need day to day to make and debug iOS applications. You still need Xcode to archive and upload to iTunes.

I just meant I invested some time to learn how to use those tools and setup vim to work with Objective-C and Swift so I don't need to Xcode which is trash because its slow and unstable and its a pain in the ass to install plugins for it.

Xcode doesn't even let you refactor Swift code yet which is a major issue.

>>61908308
I don't have an iPhone 4 or iPad so this is handy to at least see layout. Simulator for iOS is fast as fuck compared to Android.
>>
do you guys think the average joe has the potential for programming? I ask because I look back and it's taken some serious amounts of autism for me to really make progress, and I really wonder if the average person is really willing to sit there and tediously debug their programs for hours on end.
>>
>>61912726
>>61912713
>sorry fucked up the formatting,
this is what you get for using tabs instead of spaces

>what is happening/what it means to increment a string
move to the next char in the string
>use it as an if condition.
evals to false if the pointer is null (string is empty/ invalid)

as for the while (*end)
it evals to false when we reach the end of string byte

so basically it increments the end pointer until it gets to the end of the string, then the while (str < end) does this

makes tmp = to the char that str is pointing at
makes the char that str is pointing equal to the char that end is pointing at
increments str to point to the next char
makes the character pointed at by end = tmp
decrements end
the while loop ends when str and end pass eachother, ie the entire string has been reversed
>>
File: lewd shota.png (756KB, 935x883px) Image search: [Google]
lewd shota.png
756KB, 935x883px
how do i make "subst a: c:\hello\hello"

to last even after restart?
>>
>>61912713
It's not increment a "string". It's increment the pointer.
That's the same as:
tmp = *str;
*str = *end;
str++;
*end = tmp;
end--;

The if is just to check if "str" it's not a 0 length string.
>>
>>61912814
>do you guys think the average joe has the potential for programming?
basic stuff? sure
advanced stuff? no, they lack the 'tism that it takes to care enough to bother taking the time to understand this shit
look at computer science history, no one really gets into this shit without being obsessed with it.
>>
>>61912814
You could make a living doing it.

I don't know if there are people here who agree, but for me there was just a period where it clicked for me (was during reading SICP) where I understand that there are trends with most programming challenges that you need to observe and learn.

Also, debugging is the most fun part. Its like a little murder mystery that you get to be the detective and solve.

Some lower level stuff and some specific fields requires maximum autism and those you can't just whiff your way into. With anything in life anon, if it actual interests you you will be able to sit down and trudge through the boring stuff to get to the other side.
>>
>>61910481
Captain Quattro, he is a LOOP.
>>
File: brown skinned programmer.png (401KB, 523x582px) Image search: [Google]
brown skinned programmer.png
401KB, 523x582px
>>61910196

this is why a good mathematician will make a good programmer
>>
>>61912857
>>61912882

Gotchya, thanks lads.
>>
>>61910541
I think that the general consensus is that Scheme is the better designed, more beautiful language, but CL is more suited for actual development of programs.
>>
File: sdlkfhjsdkfljsdklf.png (1021KB, 1310x910px) Image search: [Google]
sdlkfhjsdkfljsdklf.png
1021KB, 1310x910px
how do i prevent running vcvarsall.bat x64 from redirecting me to my repo?

i even do cd c:/myfolders but it wont fucking work

what the FUCK
>>
>>61910838
>macrolets
will they ever learn?
>>
>>61913347
>any l*sp
>suited for actual development of programs
TOP KEK
>>
File: paul.png (120KB, 240x320px) Image search: [Google]
paul.png
120KB, 240x320px
>>61913382
excuse me?
>>
>>61913347
People repeat this trope all the time but I don't see why it should be true.

>>61913374
>blub programmers
lol
>>
File: wayland-screenshot.png (363KB, 1920x1080px) Image search: [Google]
wayland-screenshot.png
363KB, 1920x1080px
Initial version of gentoofetch is ready.
First I wrote this in dash, but now decided to rewrite it in C, it works faster, doesn't needs shell or external commands as .dash version.
Wery short, less than 200 sloc.
https://github.com/DmitryHetman/gentoofetch
>>
>>61913390
You're excused. Now kill yourself.
>>
Is there a 4chanX plugin for firefox?
>>
>>61913420

yes, you would need greasemonkey for it and there's a webpage of script that you can have greasemonkey parse.
>>
>>61913390
>suited
doesn't say capable
>>
>>61913409
did you compile gentoo with -f-no-whitespace?
>>
>>61913396
>People repeat this trope all the time but I don't see why it should be true.
Scheme has a smaller standard library, macros are different etc.

About Scheme being nicer, I think that's more how you feel but two things I like more for example is it being lisp-1, being able to call functions without funcall.
>>
>>61913428

Cheers mate.
>>
>>61913447
Why do you think so?
>>
>>61913382

That guy who's makign the minecraft clone has done a decent job using scheme.
>>
>>61913491
I'm not sure. It could be the 1-space 'tabs' used there.
>>
>>61913382
lisp can be faster than C.
>>
>>61913446
>t. blub programmer
>>
>>61913462
Racket has a standard library with a majority of the things you'd ever need to develop applications, out of the box. Some of the fringe stuff you can find in libraries, but not all. Also I suppose it doesn't have a great web development scene.

I've grown to love Racket's macro system. It's much beyond syntax-rules and it provides a much nicer way to enforce or break hygiene than most other lisps (very little need for gensym, handles cross-module identifiers perfectly, no fucking about with er/ir-transformers)

Alexis Kind posts alot of neat Racket stuff on their blog:
https://lexi-lambda.github.io/

Also this article:
http://blog.racket-lang.org/2011/04/writing-syntax-case-macros.html
>>
>>61913505
No, I prefer spaces over tabs.
>>
File: confusion.gif (2MB, 244x194px) Image search: [Google]
confusion.gif
2MB, 244x194px
I'm trying to learn Haskell but I'm starting to feel like there wasn't much of a point. I started doing Euler problems and I still couldn't even understand the Haskell solutions after cheating, then I tried them with a scripting language and burned through them easily.

Pretty much every time I want to do something, the lazy evaluation and purity seem more like a hindrance than an asset. Solutions to problems that don't exist.
>>
>>61905927
I got distracted from writing a script to automate user creation and started drawing ascii swords
          /<
/>
[//////(o)::::<###################>
\>
\<
>>
>>61913541
..and there's no harm in using 4 of them per indentation level.
I was pointing out the use of 1-space indentation, which is probably the most uncommon value that I've seen. Generally its either 8, 4 or 2 for the kids nowadays
>>
>>61913554
>I was pointing out the use of 1-space indentation, which is probably the most uncommon value that I've seen. Generally its either 8, 4 or 2 for the kids nowadays
You right, I do some programming in go, and already decided to use 2-spaces indentation, it's more clear and easy to read.
I don't like tabs becouse it's hard to read a lot of nested conditions\loops (I can't see whole line).
>>
>>61913547

Have you done SICP?
>>
>>61913552
Can you automate the writing of '8==э' ?
>>
how do i take the center item of a python list?
this doesn't work
halLen = ((len(LIST))/2)
pivo = LIST[(halLen - 1):halLen]

trying to make a quicksort
>>
>>61913611
oh, wait, it's probably getting adouble as halLen, isn't it
>>
File: 015.jpg (344KB, 1605x655px) Image search: [Google]
015.jpg
344KB, 1605x655px
>he still uses the obsolete language
It's time to move on.
>>
File: nani22.png (401KB, 720x672px) Image search: [Google]
nani22.png
401KB, 720x672px
>>61913623
what did she mean by this?
>>
>>61913611
list = [1, 2, 3]
center_index = len(list) // 2 #py3
center_index = len(list) / 2 #py2
>>
>>61913589
No, but Lisp is quite easy to grok, since it lacks the autism I mentioned.
>>
>>61913591
Here's the output, let's see if it worked.
………………………………………._¸„„„„_
…………………….…………...„--~*'¯…….'\
………….…………………… („-~~--„¸_….,/ì'Ì
…….…………………….¸„-^"¯ : : : : :¸-¯"¯/'
……………………¸„„-^"¯ : : : : : : : '\¸„„,-"
**¯¯¯'^^~-„„„----~^*'"¯ : : : : : : : : : :¸-"
.:.:.:.:.„-^" : : : : : : : : : : : : : : : : :„-"
:.:.:.:.:.:.:.:.:.:.: : : : : : : : : : ¸„-^¯
.::.:.:.:.:.:.:.:. : : : : : : : ¸„„-^¯
:.' : : '\ : : : : : : : ;¸„„-~"
:.:.:: :"-„""***/*'ì¸'¯
:.': : : : :"-„ : : :"\
.:.:.: : : : :" : : : : \,
:.: : : : : : : : : : : : 'Ì
: : : : : : :, : : : : : :/
"-„_::::_„-*__„„~"
>>
>>61913654

list[center_index]
also dont overwrite list in the namespace, i'm just retarded.
>>
>>61913623
C++ and Rust suck though.
>>
>>61913656

I'd go though SICP if I was you. Does a decent job of explaining the benefits of lazy evaluation in the first chapter. The little lisper is a good book also to learn from. If you just wana get shit done though, give it a pass.
>>
>>61913706
are you a bot?
>>
>>61913692
I know what lazy evaluation does, I just don't think it should be default.
Though mostly I hate the statelessness since so many problems are easier to deal with even if you only change state in one line of code. I don't give a fuck about side effects.
>>
>>61906224
Why do you need a boot screen, anyway?
>>
File: casey irl.png (2MB, 1535x1017px) Image search: [Google]
casey irl.png
2MB, 1535x1017px
Casey from Handmade Tutorial made it into an anime
>>
File: just-shove-it-57b1f7320439d.png (143KB, 326x367px) Image search: [Google]
just-shove-it-57b1f7320439d.png
143KB, 326x367px
Umm... I think I fucked up.

I've been writing a messaging program/framework with ZeroMQ for a few weeks now and ZeroMQ has been nothing but great so far.
But I just realized, that in the PubSub protocol (which is used to send users incoming messages) ZeroMQ doesn't have the option to prevent users from subscribing to literally all message topics at once. There's no exact matching of topics -- if a randomly generated topic of some user starts with an FF byte, then anyone can subscribe to the FF topic and get all messages of that user. Or just subscribe with a zero-length topic and get all the messages.

What do?
I really, really like ZeroMQ, but how come the devs haven't added an option for exact topic matching in years of the project's existence is beyond me.
>>
is it possible to make cmd just open my executable and actually let me use the cmd?
>>
>>61913994

woops, pic related
>>
>>61914002
Google is your friend, or alternatively RedHat, Cannonical, Apple, ... anything besides Microsoft
>>
>>61914002
Rephrase your goa. I don't understand what you want to do.
>>
>>61914002
Also: ADMINISTRATOR FFS! Quit using a computer ever again, kiddo
>>
>>61914071

when i do 'sublime_text.exe' the command line will open up sublime text but it wont let me use the cmd anymore, i have to close sublime text, then terminate the batch, then i can type in the cmd again,

i just want it to open up sublime and doesnt freeze.
>>
>>61914071
>>61914002
No son't bother rephrasing your sad-ass question: if anon replies to you I'm kicking him in the balls for encouraging this distracting behavior of yours. Get lost!
>>
>>61913921
Huh. Just read the docs, turns out all the network patterns that I use now will be deprecated in favor of sane alternatives that fix all the outstanding problems, as well as the problems that I worked around recently.

Yeah, no thanks. Onto the next messaging queue I go.
>>
Found out that Mega.nz has a command line client, trying to think of a project or anything to use it for but can't think of shit - suppose it's only actually useful for large data deployments or something
>>
File: dump apuuu.png (37KB, 1127x685px) Image search: [Google]
dump apuuu.png
37KB, 1127x685px
>>61914094

prease no burry senpai
>>
could a voxel engine that dont keep the voxels as geometry but draws them by a geometry shader work?
so you would just push a mesh that consists of the centre points of the voxels and the gpu does the rest.
>>
>not a webdev
>don't have 5 billion shitty js libraries to shit onto my resume to fill up space

What do normal people put under their skills sections of their resumes
>>
Trying to read a maze from a text file and saving the characters in an array in Java.
Currently getting NoSuchElementException when copying the chars in a nested forloop and I can't see what's wrong.
public Maze(java.io.Reader fileInput) throws IOException
{
boolean colCounter = false;
ArrayList<Character> buffer = new ArrayList();
BufferedReader reader = new BufferedReader(fileInput);
int readChar;
//Row starts as one to count for EOL.
rows=1;

//Read through file to get rows and columns.
while ((readChar = reader.read()) != -1)
{
if(!colCounter)
{
cols++;
}

if( (char)readChar == '\n')
{
colCounter=true;
rows++;
}

else
buffer.add((char)readChar);
}

Iterator<Character> mazeIterator = buffer.iterator();
mazeData = new Character[rows][cols];
for(int r = 0; r < rows; r++)
{
//loop through the columns of each row
for(int c = 0; c < cols; c++)
{
mazeData[r][c]=mazeIterator.next();// NoSuchElementException
}
}
}
>>
>>61914190
Manually accessing iterators is doing it wrong. Just use a foreach loop nigger.
>>
File: java.jpg (155KB, 724x810px) Image search: [Google]
java.jpg
155KB, 724x810px
>he doesn't use java
>>
>>61914269
Java hurts me.
>>
>>61914200
I see what you mean, I fixed and I no longer get any errors but when I try to to print the maze I only get NULL printed instead of the character I wanted.
for(int r = 0; r < rows; r++)
{
//loop through the columns of each row
for(int c = 0; c < cols; c++)
{
while(mazeIterator.hasNext())
{
mazeData[r][c]=mazeIterator.next();// NoSuchElementException
}

}
}
>>
>>61914274
you must be a weak bitch
>>
Microsoft Visual Studio is fucking hell
>get error
>takes hours of searching to fix it
>now the compiler doesn't work as intended
>takes hours to fix
>no project names changed
>re-install
>same first error appears
fucking shit
>>
Stuck.

#include <iostream>
#include <string>
#include <vector>
#include <iterator>

using namespace std;

int main()
{
string word, consonant;
//char letterList[21] = { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' };
vector<char> newForm;

cout << "Enter your word: ";
cin >> word;

for (auto c : word) {
if (c == 'b')
consonant = c;
else
newForm.push_back(c);
}

copy(newForm.begin(), newForm.end(), ostream_iterator<char>(cout));
cout << "-" << consonant << "ay" << endl;

return 0;
}


So I can check for 'b' but how do I check if it's any consonant at all. I'm looking for a way to do this.
>>
I'm told abs() branches in glsl.
I don't see why. Shouldn't that just do AND with the sign bit?
I don't see why it'd ever branch.
>>
>>61914966
Use std::find.
>>
>>61914966
or use std::set_intersection
>>
>>61914966
Create a flag 'is consonant' (boolean) and set it to false.
Loop through the list of consonants and compare them to c. If c is equal to any of them you set the flag to true and break. Use the flag to determine if c was a consonant.
Remember to always set the flag to false at the start of the loop.

You could also write it as a function. Which is way nicer.
>>61914997
Or use sepples i guess. I don't know sepples. It's probably better.
>>
// Dictionary.h
class Dictionary {
private:
std::set<std::string> words;
public:
Dictionary(std::string);
bool contains(std::string const&) const;
};

// Foo.h
class Foo {
private:
Dictionary dict;
...
type bar();
};


How do I initialize dict for use by bar within Foo.cpp?
>>
>>61915080
I don't understand the question.
>>
#include <cstddef>

#include <tuple>

namespace core
{
template <class>
struct function_traits;

template <class R, class... Tn>
struct function_traits<R(Tn...)>
{
typedef R return_type;
typedef std::tuple<Tn...> parameter_types_as_tuple;

static constexpr auto arity = sizeof...(Tn);

template <std::size_t Idx>
struct at
{
typedef std::tuple_element_t<Idx, parameter_types_as_tuple> type;
};
};

template <class R, class... Tn>
struct function_traits<R(*)(Tn...)> : function_traits<R(Tn...)> {};
}

int main(int, char**)
{
core::function_traits<decltype(main)>::template at<0>::type i = 0;
return 0;
}


R8 my code.
>>
>>61915111
template hell/10
>>
>>61915080
You'd use a constructor or initializer member function. Since it's private only the class can touch it.
>>
Working on the initial stages of an R7RS Scheme interpreter in Go. Just messing with the lexer for now, but since it's Scheme this stage shouldn't take long at all.
>>61914002
>>61914082
See here: https://superuser.com/questions/198525/how-can-i-execute-a-windows-command-line-in-background
I'd personally write this off as too involved for what you want to do (why not just make a shortcut or something), but whatever floats your boat, anon.
>>
>>61915120
It's not even that bad measured by average template use.
>>
>>61914997
find(.begin(), .end(), valueInArray[])

How could I check if the element in a vector matches up with any of the elements in an array? I've only found examples with non arrays so far.
>>
>>61915169
std::equal or std::any_of
>>
>>61915169
std::find(arr, arr+len, val) == arr+len
>>
>>61915169
also, if you use an std::array: all of the <algorithm> and <iterator> stuff will work. why use C arrays when you're going to be using c++? even then, vectors are generally sufficient as a general purpose container
>>
>>61915232
What are the downsides of using a std::array instead of a C array?
>>
>>61915201
Is std::find smarter than just a binary search?
>>
>>61915254
I'm pretty sure it's just a linear search, it doesn't make any assumptions about the container being sorted so it can't do a binary search.
>>
>>61915247
There's technically no downsides.
>>
>>61915254
>>61915270
But I see now that std::binary_search is a thing, so maybe you want that.
>>
>>61915247
std::array have sizes known at compile time.
C array can be of arbitrary size, so you must pass the array size to functions.
>>
>>61915247
off the top of my head, the only "downsides:"
std::array doesn't decay to a pointer. (which isn't a downside imo. static typing is quite useful.. but C programmers might want to pun an array with some other type..)
it takes more boilerplate to use std::array in places that expect a C-style array (basically using .data() and .size()) instead of just passing in the array.
there's more mental overhead for people who aren't used to STL containers.
and ofcourse: more typing is required, but thats slowly being fixed in newer C++ standards.
>>
>>61915309
also this, but thats why std::vector exists :)
>>
>>61915319
Is there a type and size inferring pseudo-constructor? Something like std::make_tuple.
>>
>>61915334
There is in C++17 with deduction guides, but something like make_array is trivial to write.
>>
>>61915327
No sts::vector are not C arrays.
>>
>>61915327
>Having to heap allocate when you want a variably sized array
meh
>>
>>61915293
Since when just working with the consonants he probably wants a linear search. They're gonna be very similar in performance but I'm pretty sure the CPU will have an easier time prefetching the consonant array in the linear search case. Normal cache lines are 64bits (8bytes/chars) so you're not gonna get it loaded all at once.
Waiting in that case can be very slow. So it's wiser to give the CPU the opportunity to fetch intelligently.

Now you could have a very smart CPU that understands that he's gonna want the entire array from context. But I'm not confident they're that smart.
>>
What is this called?

char c = "hello"[n];
>>
>>61915394
That isn't special.
>>
>>61915394
Assigning the content of the cell of a char array to a char variable.
>>
>>61915426

 char c = "hello"[0];


c = 'h' ?
>>
>>61915444
yes
>>
>>61915444
Yes.
>>
File: pic2.jpg (68KB, 1166x831px) Image search: [Google]
pic2.jpg
68KB, 1166x831px
Pretty new here but:

I'm having a hard time understanding the syntax that you use with hashing, can only ever find Java examples but I'm working with C#, I know full well of what the idea of hashing is and what it's used for, but I can't wrap my head around actually making the whole thing into an array of sorts.

Let me know if I'm just talking shit at this point I've been up for ages
>>
>>61915444
char c = 0["hello"];
>>
>>61915466
yeah, this syntax is weird. c defines [] as
a[b] = *(a+b);


so
"hello"[2]
will evaluate to
*("hello" + 2)
while
2["hello"]
will evaluate to
*(2 + "hello")
>>
>>61915501
Thanks, captain.
>>
https://www.youtube.com/watch?v=s4wnuiCwTGU
How do I run multiple optimization passes in GCC?
It seems it should be necessary. Do you people run multiple optimization passes?
>>
>>61915102
>>61915131
Can I trouble you for some example code? Everything i've tried so far is bunk.
>>
>>61915464
I assume you're talking about the mod operator.
a %= b is the same as
a = a % b;

% is the modulo operator (remainder in basic arithmetic.. (technically Euclidean division))
>>
Anyone mess with STM before? https://en.wikipedia.org/wiki/Software_transactional_memory

Seems pretty straightforward to implement for a functional language, so I was thinking of throwing on the planned feature pile for that Scheme interpreter of mine.
>>61915464
Is that your code? Aside from implementing the ability to write to the hashtable (which is just grabbing the new value's hashcode and throwing it into the relevant index in your array), that's basically it.
>>
>>61915539
Your dictionary there is a member variable so you can initialize it in your foo constructor. Unless I'm misunderstanding?
>>
>>61915520
That's a compiler internal. Just use
gcc -O3
if you're worried about performance. Though frankly at that point you'd be better off with a better algorithm, but if you're trying to squeeze that last little bit out of your code, might as well try the flags.
>>
File: 1492833251142.jpg (475KB, 852x973px) Image search: [Google]
1492833251142.jpg
475KB, 852x973px
>>61915563
Yeah it's a rough DIY I did on a template that was up on the screen at college, but thanks for the legit input I'll get on it

>>61915546
Oh fuck I completely forgot about modulators, thanks
>>
>>61915593
>That's a compiler internal.
Yeah, he's having llvm work over the IR once more.
I'm wondering if I can make GCC do the same.
>-O3
He never showed O3 but I'm assuming if it was that simple then he'd have done it right?
>>
>>61915579
like this?
Foo::Foo(std::string s) {
dict = Dictionary(s);
...
}

the data doesn't persist like this.
>>
>>61915610
More like this.
Foo::Foo(std::string s):
dict(s)
{

};

But pretty much. What do you mean it doesn't persist?
>>
>>61915605
also, using -fprofile-generate / -fprofile-use and -flto if you want more indepth analysis done while optimizing (PGO and LTO)

>>61915610
because your allocating it on the stack, when it goes out of scope the dtor will be called. use a smart pointer (std::make_unique, std::make_shared, etc), or be a curmudgeon and use new to heap allocate it
(this is a very important and useful concept called RAII)
>>
>>61915647
Nothing you said there has anything to do with this.
>>
>>61915647
it was a guess at what he meant by "data doesn't persist .." (assuming Foo is leaving scope [not shown], killing dict, etc)
>>
New thread
>>61915702
>>61915702
>>61915702
>>61915702
>>
>>61915637
this gives me the error "type 'Dictionary' does not provide a call operator"

I mean that something like the following doesn't work as
dict.size()
returns 0.
Foo::somefunc() {
if (dict.contains(str))
...
}


>>61915647
I think what you've described is the case. I'll have to read about make_unique/make_shared. I tried modifying the code for heap allocation using the new keyword, but attempting to access dict led to segmentation faults then.
>>
>>61915748
>this gives me the error "type 'Dictionary' does not provide a call operator"
Then you're misreading my code and are probably unaware of constructor initializer lists. Whatever, it's not terribly important. Show me your Dictionary constructor.
>>
>>61915775
>>61915807

Any ideas?
>>
>>61915881
>>
>>61905927
recommended reading for people who do high level programming and who want to get into low level? (I'm in love with the ESP32)
Thread posts: 345
Thread images: 36


[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.