/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

github.com/UlfNorell/x86-agda
twitter.com/SFWRedditGifs

Thoughts on Android development from a technical standpoint? Is it more powerful / better than iOS?

Install Pelles C.

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.

Because I like to do more with my code than math and have pointers referencing pointers referencing pointers

Because C89 is dire.

does flashing a graphics card for OSX use count?

its an absolute bitch and worried about bricking my precious

flashing a GPU happens at the firmware level, so the OS shouldnt matter unless you're doing something whacky

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.

>c11
>not gnu11
Way to stay irrelevant gramps

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

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.

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.

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?

No reason not to use C11 on embedded.

({ })
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

github.com/UlfNorell/x86-agda

C++

Other than no compiler supports it

CISC is deprecated, user.

Pelles C supports C11.

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

Small Device C Compiler. Supports everything relevant not supported by GCC or Clang.

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

Tell me more.

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.

No, I've told you enough.

>AT&T syntax
TL;DR

x86_64 is not deprecated; it has no valid replacements.

It's a detail.

%it's %a %detail

Of course.

I am, actually. I don't like how C11 redefined the abstract machine. The threads support is crap.

Still waiting.

It's been a while, I'm rusty. What syscall is this? Linux has no syscall 0

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.

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

xor %rax, %rax
rax is 0
mov $50, %al
rax is 59
so when the pc reach syscall rax is 59

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

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?

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

>Wtf does it point to?
Just follow the code user.

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

>hs//nib/

Wot

You read it in the wrong order user.

>/bin//sh

Cool, a valid path
Is this because of little endian bullshit of Intel

Going from lower to higher, is the best order. So Intel is right.

Aight.

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

I see you also move stack ppinter to rsi. Hmm...

You need rsi to have a decent shell, otherwise starnge things happen

>mov rsp, rsi
>rdi was last pushed to stack
>rdi contains pointer to filename

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

???

Yes. But to be precise, after the pointer to filename there is a null pointer (push %rax), argv has length 2.

Reminder

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

How am I supposed to do low level development using only functional programming languages?

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.

It's a joke. It's certainly not practical to only know and use those three.

what if you want to do anything lower level than "code artisan"?

>what is pre-scheme

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/?

bunch of vocabulary words for the GRE

ASM monad

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.

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

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

How easy hotswapping code is in C.
I don't like it. C shouldn't be the best language.

how are you supposed to use that effectively without knowing assembly?

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

Look at the types

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.

How to run lldb with xcrun so I don't have to use fucking xcode anymore.

lldb is awesome.

that's too easy

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

forgot my image.

Having a poke around the Health app on iOS

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

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

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);

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.

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. :)

foo paren

int ecks equals wun

foo paren bar

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

>call foo
>int ex equals one
>call foo with bar

nice!

why not emulate the app on a physical iPhone?

isn't it faster? at least on Android

what is this font senpai

what about if(x == (y + (5 - foo(bar)) / 2)))

>~/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

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

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

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 "

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

A scratch/snippet folder is what I was missing! Hopefully that'll make things a bit neater

the ascii symbol '?' is represented as the integer 63.
You interpreted an ascii character as an integer.

You're converting the question mark to its ASCII code, which is 63.

>if x equals y plus 5 minus call foo with bar over two

If they want the details they can read the code

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

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.

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?