/dpt/ - Daily Programming Thread

Old thread: What are you working on Sup Forums?

Other urls found in this thread:

youtube.com/watch?v=icqPHsNumuU
stackoverflow.com/questions/9685699/what-is-global-offset-table
en.wikipedia.org/wiki/Position-independent_code#Technical_details
grantcurell.com/2015/09/21/what-is-the-symbol-table-and-what-is-the-global-offset-table/
refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_zSeries/x2251.html
en.wikipedia.org/wiki/Indent_style#Variant:_1TBS_.28OTBS.29
quora.com/Why-is-the-popularity-of-Ruby-falling
twitter.com/SFWRedditImages

First for Nim!

2nd for please help me find a babby project I can do.

if ( !std::is_integral::a )
{
a = rand();
}
if (a == true)
{
// do work
}


Why is this not valid C++?

>no anime image
>created before bump limit
kill yourself

write a script that generates a list of babby projects that you are capable of programming.

Preparing on a job interview

...

I'm sorry I'm a beginner and I don't think I understand what you're saying. Do you mean that I'm not actually jumping into the GOT but directly at the address of my main function? If so, why isn't the program jumping to 7d0 (that's the address of my main)?

This post is hate speech.

Write a program that allows you to rate the negativity value of text from 1 to 10. 1 being the least mean and 10 being SAVAGE.

is that better?

youtube.com/watch?v=icqPHsNumuU

What keeps python popular? Is it because of the memes or are there really a use for it?

Because it's already popular

Same reason as Java

It's easy to learn and has a ton of libraries. Its FFI mechanism is also easier to use than the one of other languages, from what I read.

...

It's only popular because it pulled of a 'gimmick' of whitespace retardation and people fall for that

>GUI builder
dropped

Reposting here because I don't understand the answer I was given in the other thread:
I'm looking at the disassembly of a very simple program (void main() {}) and trying to understand stuff. The libc is compiled as a shared library. Now in my binary I have the following piece of code:
0000000000000680 :
680: ff 25 42 09 20 00 jmpq *0x200942(%rip) # 200fc8
686: 68 02 00 00 00 pushq $0x2
68b: e9 c0 ff ff ff jmpq 650
From what I understand I am jumping somewhere in the global offset table. How can I find out where exactly in the libc I am jumping? I tried looking at various addresses in a disassembly of my libc.so but I can't find anything that seems right.

to the javafags out there, what do you think of Lambdas and the Streams API?
do you use it? at work?

That looks interesting. What tools are you using?

It's Probably jumping for a print command or some other library functionality.

Visual studio can follow code into libraries you don't have source code to by showing you the assembly code and you can step through it in the debugger. So if linux has that type of debugging use that, otherwise give up because debugging massive libraries in ASM won't be useful or good for your sanity.

not a javafag but you should use lambdas

Why is that?

they're fundamental to programming

Objdump, readelf and neovim. I'm a newbie really. I know I could use GDB instead of objdump but I feel like I'd learn more things with plain old objdump.

>Probably jumping for a print command
Highly doubt it since the source code is just void main() {}. I think it's a libc setup function but I can't find which one exactly.

Thanks user but I'm not trying to debug massive libraries, I just want to learn what's happening behind the scenes.

I don't understand. I can do the same thing iteratively and it is more readable.

no it isn't

This looks like objdump to me. Have you tried looking at the assembly output generated by your C compiler? It usually has proper function names.

stackoverflow.com/questions/9685699/what-is-global-offset-table
en.wikipedia.org/wiki/Position-independent_code#Technical_details
grantcurell.com/2015/09/21/what-is-the-symbol-table-and-what-is-the-global-offset-table/
refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_zSeries/x2251.html

You should find the GOT, from the last link:
>The Global Offset Table resides in the ELF .got section.
After that you can just find out where that entry points, etc. There might be an easier way, probably there is some kind of tool which does this for you.

I haven't done shit like this for a long time, especially on a unix-like system though.

[citation needed]

Thanks for the explanation.

>What are you working on Sup Forums?

#include

main()
{
int numero, i = 1;
for (i = 1; i

Use Allman style bracing.
Use braces even for single line conditionals/loops

if (condition) {
process();
}

>The Global Offset Table resides in the ELF .got section.
Thanks a lot user, objdump -d doesn't seem to show the content of the .got but objdump -D does, that's why I couldn't find anything. I've been stuck on this thing for something like an hour now, thanks again!

I mean use K&R and not Allman.
K&R:
if (condition) {
process();
}


Allman:
if (condition)
{
process();
}


makes you less retarded.

>Use three lines for something that can be done in one
disgusting.

if (condition) process();


Asymmetrical braces are an abomination.

m8 void main() {} isn't going to teach you much of anything useful.

write some actual code in your program and that dissemble that.
if you use gcc you can use the flag -S to output disassembled code and take a look.

That shit is probably just bookkeeping. Your program has to be allocated some stack memory and spawned by a task scheduler process. I couldn't tell you what that ASM was actually for, and I don't think it's incredibly useful to know. Might be an interesting question for an expert but I fear the answer may be underwhelming and boring.

It's almost as if everyone had a different taste.

You're welcome.
As far as I know gcc can produce an assembly file with the -S switch. There is also a switch for producing Intel style assembly too (this applies to objdump as well).

that's even more retarded especially if you have complex conditions

I'm using Allman and there's nothing you can do about it!

[code{
}
[/code]

vs
{

}


is taste.

bloat vs not bloat is objective.
If it's something relatively simple as that, it's fine.

enjoy your 100% wider codes
enjoy your 100% taller codes

Something as simple as void main () {} already taught me about the Global Offset Table (I didn't even know it existed). I'm sure there's plenty more to learn.
I'll try using a real program once I understand what an empty program does.

Thanks for the advice, I'll make sure to check out what gcc -S does if I even get stuck again.

Except of course complex progress require complex conditions and by your logic, consistency is bad.
Consistency == Readability

enjoy your non-problems

It may be marginally taller but at least I can tell where the damn things open and close.
If operated a 24x80 terminal I might be more inclined to conserve rows.

why?

>Javafags doesn't indent switch statements
switch (value) {
case 1:
processOne();
break;
case 2:
processTwo();
break;
default:
doDefault();
break;
}

If it's simple, no braces.
If it's not simple, braces.

Quit being so dense, Sup Forums.

...

QUICK, MAKE A PROGRMA THAT PRINTS FIZZBUZZ FROM N TO K (ARGV), BUT CHANGES ITS SOURCE CODE EVERYTIME TO UPDATE HOW MANY FIZZES, BUZZES, OR FIZZBUZZES IT HAS DONE, THESE SHOULD BE VARIABLES OR PART OF A COMMENT IF YOU WANT (FORMAT DOESN'T MATTER, JUST KEEP A COUNTER)

E.G
$ ./fizzbuzz 3 6
fizz
4
buzz
fizz
$ cat fizzbuzz.lisp
; fizzes = 2
; buzzes = 1
; fizzbuzzes = 0
...

That's how you goto fail though.

switch (value)
{
case 1: processOne(); break;
case 2: processTwo(); break;
default: doDefault(); break;
}
2bh

'no'
not 2bh

1TBS
en.wikipedia.org/wiki/Indent_style#Variant:_1TBS_.28OTBS.29

Neat.

>if (x < 0) {
puts("Negative");
} else {
nonnegative(x);
}

non-readable garbage.

except that you do

if(condition) {
thing();
}

Even if it is just one line and one thing.
The block is there so that you are explicit about what is inside and outside the scope of the if statement.
That way you can be half-asleep and slightly drunk at 02.00 and still not fuck up.

>indenting the closing brace
jesus christ how horrifying

>That way you can be half-asleep and slightly drunk at 02.00 and still not fuck up.

I can already do that just fine.
Sup Forums really needs to stop worshiping old and busted styles.

Let me guess. You name your variables int a, int b; too right?

Why, so we can make the same mistakes all over again and reinvent them?

Obviously int i; int j; is superior.

>int a, int b;
Is this even possible? I thought it was int a, b;

Obvious typo. Reflex had me declaring it separately.

int smthng,smthng2;

If my no-vowels variable stops being explicit, i change it.

>not logical
int p, q;

Preposterous! The naming convention of I and J have been used in a PLETHORA of code examples and are therefore superior and standard.

I would be bewildered by the use of a for loop defined with p as a counter, followed by a subsequent but equally confusing loop using the counter q.

I and J vastly show more intent than the arbitrary values of p and q.

he's just shilling javascript culture properties. It's a regional manager thing but in dealing with the time constraints over the regional ones. It's supposed to be more "meaningful". You know these totalitarian governments wearing sombreros. It's ridiculous.

Wait, people still unironically use loops with counters in them?

I bet you even make the loop check that the counter is less than the length of an array, Mr. 1995.

Only retards use j. It's i and k for obvious reasons.

and what's next? l?
Inconceivable!

tell me what replaces loops? looping is the basis for any program to run. If your program does not loop it dies.

Is there an emerging new fad like ruby was that I can jump into?

I'm tired of the same bullshit.

Fuck no. It's m.

I'm trying to do thread synchronization inside a function, kind of with a parallel for. Its for a game simulation loop, that's why its synchronized.

First, I create a boolean for each thread I'm about to launch - they are initialized to 0, meaning that thread's job is not done yet.
Then I pass a pointer of the boolean to each one of the threads. When the thread's job ends, they turn theyr boolean to true.

Lastly, inside the function, after launching each one of the threads, there's a while loop (spinlock, so to speak) that tests all those boolean values. If they're false, it won't exit the function.

The problem is that the other threads set those booleans to true, but the main thread that launched the threads never seems to receive this update. It always reads the booleans as 0. I've tried the win32 API InterlockedCompareExchange, setting the bools to volatile and whatnot, but the spinlock always stays in an infinite loop.

Oh, and by the way, the language is C, and the threads are not actually created inside this function, but they're from a thread pool (I add a job for each job to the pool, after which they go back to sleep.)

Any ideas what could be wrong? And if I didn't explain it well, I can write up a code example.

Syntax sugar.

ikm
i kno m80
pottery

What obvious reason would that be?
I typeically use l i and j as my standard variable names. It's called the programmers arch because of the shape it makes on a QWERTY keyboard.

Recursion with unlimited stack

Rust if you're a tranny.

:^)

Google is releasing a new meme language called Dart.
I think node.js is pretty trendy too.

I don't know much about ruby, why was it a fad and was it good/easy to learn or just a new popular language?

objdump -D > name.asm


the > pipes the output to a file called name.asm, which you can open with any editor. linux/unix tip

here's my
int void main(){return 0;}


compiles into this with gcc

how do i optimize?

a.out: file format Mach-O 64-bit x86-64

Disassembly of section __TEXT,__text:
__text:
100000fa0: 55 pushq %rbp
100000fa1: 48 89 e5 movq %rsp, %rbp
100000fa4: 31 c0 xorl %eax, %eax
100000fa6: c7 45 fc 00 00 00 00 movl $0, -4(%rbp)
100000fad: 5d popq %rbp
100000fae: c3 retq

_main:
100000fa0: 55 pushq %rbp
100000fa1: 48 89 e5 movq %rsp, %rbp
100000fa4: 31 c0 xorl %eax, %eax
100000fa6: c7 45 fc 00 00 00 00 movl $0, -4(%rbp)
100000fad: 5d popq %rbp
100000fae: c3 retq
Disassembly of section __TEXT,__unwind_info:
__unwind_info:
100000fb0: 01 00 addl %eax, (%rax)
100000fb2: 00 00 addb %al, (%rax)
100000fb4: 1c 00 sbbb $0, %al
100000fb6: 00 00 addb %al, (%rax)
100000fb8: 00 00 addb %al, (%rax)
100000fba: 00 00 addb %al, (%rax)
100000fbc: 1c 00 sbbb $0, %al
100000fbe: 00 00 addb %al, (%rax)
100000fc0: 00 00 addb %al, (%rax)
100000fc2: 00 00 addb %al, (%rax)
100000fc4: 1c 00 sbbb $0, %al
100000fc6: 00 00 addb %al, (%rax)
100000fc8: 02 00 addb (%rax), %al
100000fca: 00 00 addb %al, (%rax)
100000fcc: a0 0f 00 00 34 00 00 00 34 movabsb 3746994890844667919, %al
100000fd5: 00 00 addb %al, (%rax)
100000fd7: 00 b0 0f 00 00 00 addb %dh, 15(%rax)
100000fdd: 00 00 addb %al, (%rax)
100000fdf: 00 34 00 addb %dh, (%rax,%rax)
100000fe2: 00 00 addb %al, (%rax)
100000fe4: 03 00 addl (%rax), %eax
100000fe6: 00 00 addb %al, (%rax)
100000fe8: 0c 00 orb $0, %al
100000fea: 01 00 addl %eax, (%rax)
100000fec: 10 00 adcb %al, (%rax)
100000fee: 01 00 addl %eax, (%rax)
100000ff0: 00 00 addb %al, (%rax)
100000ff2: 00 00 addb %al, (%rax)
100000ff4: 00 00 addb %al, (%rax)
100000ff6: 00 01 addb %al, (%rcx)

>how do i optimize?
-O3

>int void main
nigga you gone fullretard. don't ever go full retard.

>was it good/easy to learn or just a new popular language?
all of the above

quora.com/Why-is-the-popularity-of-Ruby-falling

Does anyone have a hint for me or can tell me if my thought is correct?

If I want to search for all divisors of a number, I just have to check if it is divisable for which numbers from 2 to 10 and then just get the multiples of those which are also sammler then the triangle number, right?
Or is there a way faster way?

I do full stack web dev shit now, but I used to be into writing binary software in C/C++. Working on a web-based SaaS startup with a friend with domain knowledge of the industry we're targeting. I hate having to make money. I just want to try my hand at writing a Gameboy emulator for fun -.-

>sammler
smaller*
top kek

>binary software
stopped reading there
the fuck does that mean?

Just write an ASM program directly with:

HLT

and compile

Oh damn, I am an idiot. I haven't thought about multiples of primes. Fuck me.

software that compiles into a binary obviously.
fucking skids these days do not even know what a binary is. do you know what JIT is?

You've never heard of writing compiled software as developing binary software? You're creating binaries directly with languages like C/C++. You a first year CS student?

How hard is Java to learn if you already know a few other OOP languages?

Define 'know'. If you really know another language then it won't be hard at all to start using Java

Not very.
The language itself isn't very hard, but you have to learn toolchains on top of it.

Not at all. It's one of the easiest and cleanest language out there to learn. Very consistent.

LMAO, your little hateful fit was DELETED