/dpt/ - Daily Programming Thread

Undefined behaviour edition.

Previous thread: What are you working on Jow Forums?

Attached: 1486600270082.png (1000x1400, 1.31M)

Other urls found in this thread:

github.com/OpenIB/OpenIB/issues/290
github.com/Cloudnaut/HFFDC/
twitter.com/SFWRedditGifs

Attached: Screenshot_20180820-134927_Materialistic.jpg (1080x698, 146K)

Page 300 of Kings C, should I finish this shit?

I want to write an emulator.

I don't know C++, just C.

Should I write it in C or should I learn C++ first?

Never wrote an emulator or had an urge to use C++ over C.

just do it in C you won't gain much from C++

write it in crystal

>writing anything big without OOP
lmao

>in b4 frothing FP autist rage

>being an OOPsie
I use FP on my MarcOS by the way.

I'm trying to convert something like this:

public class MyApp extends AppCompatActivity{

Timer timer;

timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// Over 1000 LoC I want removed from the UI thread
}
});
}
}, 100, 250); // starts .1 seconds in and continue to execute every 1/4th of a second.

into an AsyncTask, so that my app will stop occasionally crashing.

I'm working on becoming a "professional" programmer, meaning: I want to write solid as fuck & squeaky clean code.

I actually work in the industry since 2010, but I always was that guy who just "made it work". I've got a new job 2 years ago with colleagues who aren't just programmers, they are craftsman. I got inspired by their code and work ethic, so I plunged into Uncle Bob's Books with the goal of not writing shitty code anymore.

It's been a fun ride so far, but it I can't shake the feeling that it made me behave like an autist.

Freshman devs are actually scared of my code-reviews because they know I'll hit that rejected button faster than they can push any changes.

Are you French?

That's a good thing.

Autism is power in the professional world

>craftsman
No people that use that title deserve it.

No

What programming degree should I aim for? Or at least what prerequisites should I knock out in my first year?

My first reply in Jow Forums please no bully.

I'm trying to get this working, the OpenIB. github.com/OpenIB/OpenIB/issues/290

I haven't programmed in about 10 years. To me, it's all the same.

Attached: Screen Shot 2018-08-20 at 12.23.28 PM.png (1170x915, 259K)

good bait

Computer Science, but focus on your gen eds (take them at a local community/state school if you can), because that's what you should do in almost every program

It is possible to do the bresenham line algorithm for the 8 octants without the use of float numbers ? And i am not taking about the general algorithm, I want to use the formula for each octant

do I really have to free() at the closing of my program?
The OS does it anyways right?

It's good practice but I guess you don't have to.

keep fighting the good fight

Depends what you're freeing my dude.

good practice killed my uncle

Is there a gnu/linux library to read memory of a process? (c/c++)

I would like to be able to read a program library, eg. by choosing its pid

I can already do it with gdb but it requires me to freeze the process, inject a shared library in it and then defreeze it. (though my shared library will run with the program i can still read it's memory)

I know it should be possible since scanmem can do it.

>good bait

It say's What are you working on Jow Forums?

have you had a look at the scanmem source?

everything and anything(that are part of the same process)

ptrace

scanmem seems to be using it's own library

>guy mentions on his CV he's taught C and Advanced C++ for 5 years at his university during his postgrad
>ask him what's the difference between reference and pointer
>he's lost
wtf is this shit

the problem with OOP is that people design classes they don't need without thinking about the problem, then force them to work together in inefficient ways.

for instance, say you are writing a program which will format the text to be printed on a receipt. an OOP programmer would immediately think, "Oh, I obviously need a 'receipt' class". they will begin by thinking of "obvious" classes. should the program organization later on prove to only need some data (a string of receipt data with certain tokens) and a simple function (print receipt), they will have foolishly designed and interlinked many different classes and objects which are totally unnecessary. and the idea that it is somehow more readable is false, as with every class comes the standard bureaucratic clutter and alien-rune operators of the c++ standard library.

better to start with the data and the methods on that data, then design your program's organization. What is the data? How does the data need to be treated? Design the data structures as simply as possible. design the methods as simply as possible. put them together.

then and only then, design and build classes if you can't figure out a way to get by without them.

so do it in C, and if you absolutely **need** OOP then use C++.

Where i can get latest K&R book?

ptrace only allows me to pass 64bit (max) data per call

i wanna make mmo pixel game.
what language be best?

c

javascript

Once you ptrace attach you can read /proc//{maps,mem}

>>MMO
>C

enjoy the pain when you could have used OOP

>oop
this is not your first year undergrad class

first reminder of this thread that 6502 assembly won't get you a job

i don't think anyone needs this reminder

Just so you know, the guy in the pic is from the anime Himegoto

LTO problems have recently begun (again) with MSYS2. During linking, ranlib fails with "cannot rename file, already exists". Non-lto builds are fine.

I'm not sure where the problem is, but it may be autotools. lto works with other methods. The lto wrapper (gcc-ranlib) works otherwise. Only autotools generated build systems fail. Can't entirely rule out ranlib itself.

Anyone else having this?

Implemented a delta sync tool in C/C++ for super big files.

I'll use it to sync changes in my 2TB disc image to my USB2.0 external hard drive. Otherwise it takes me ages for a simple backup.

github.com/Cloudnaut/HFFDC/

Don't know if there are any equivalent finished solutions. I didn't find any

Linux kernel.

there is, it is called using a real filesystem like zfs

C++.

What's C/C++?

C++, but it'll take you years to learn it if you've never programmed before

buy a physical copy of the 2nd edition so you can put a checkmark in each box following an exercise

rsync?

Although I myself prefer C++ for this kind of projects, you can do it just fine in C.
What kind of emulator do you want to write? If this is the first one you make and you don't have a clear idea I suggest a Chip8 emulator.

> buy
can't. i'm poor.

Some company hire assembly developers
(and they don't do amd64 nor i386 since the processors running those instructions are not 'viable' enough)

Typically the buttons and handles of an airplane need to be "as viable as possible" (eg Airfrance)

why?

I'm using Windows botnet OS therefore no ZFS available.

Rsync would read the whole file from the usb drive to create the checksums everytime a copy operation has been started. This is overkill and would take ages.

C++ has shitton support for videogame
if you want to make a working multiplayer game, i'd suggest you the SFML library (it has audio, network, graphics & input).

As for the server (since it's a mmo) thereis the boost.asio library which is pretty good to do that.

Control. Widely available libraries if desired, so forth.

Why is swapping the values of two variables such a pain in the ass in C? There really isn't any good approach.

wut? it can literally be done in 3 lines in the naive solution, 1 line if you're clever.

make a function yourself you fucking retard it's 3 lines

Good analysis.
I'm of the opinion, however, that *properly structured* OO code can potentially be cleaner and more readable than purely imperative code, but I've seen very little in practice.
The problem with OOP in my opinion is not that it's an inherently bad methodology, but it is, as you mentioned, that it quite often leads you do create a bunch of classes without first reasoning about the problem at hand.
Any computer program is merely the expression of a solution to a problem. Does OO help you express it better? Use it then. Otherwise don't.
Dogmatically starting with a heavily OO approach a priori is trying to fit the problem to the solution, when it should be the opposite.

Go back to python and use a C translator.

There is literally nothing wrong with learning Python before you learn C.

So make a swap function for every type I want to swap? The temp variable type can't be declared with a macro.

I don't know python. I'd go back to C++.

>strtod and atoi are in stdlib.h
>memcpy and memset are in string.h

explain this shit

Attached: doodoo.jpg (578x722, 128K)

You could just make the parameters void pointers and take a 3rd parameter for the size of the type.
Do you also need help with fizzbuzz maybe?

Linear types will save systems programming

I want to render a simple non-interactive GPS map on an AVR8 platform, how would I go about putting a coordinate grid on an SVG, and how would I get the projection of the map to be accurate?

unsigned int myAtoi(const char * str)
{
unsigned int ret = 0;

for (unsigned int i(0); i < strlen(str); i++)
{
ret = ret*10 + int(str[i]-48);
}

return ret;
}


>He needs a library to do that

use __auto_type
if you're autistic about gnu extensions then just use auto from C++ and literally nothing else

>what is template

template void swap(T& x, T& y)
{
T temp = x;
x = y;
y = temp;
}

We are talking about C, adventurer.

why do you need to run things on vm's/docker if you could just run them on a normal machine? what's the problem with just having the one machine with all the applications needed installed on it?

It's easier to manage dependencies that way

That's what I've done, but haven't made it a function. It doesn't directly express actual intent and I don't know what the compiler does even if it's inlined.

>He needs a library for anything
>He doesn't just write functions for every architecture
>He doesn't just assume one generic solution will be acceptably optimal on every architecture

What's the difference between stack and registers?

The existing codebase is in C.

There are other reasons I'd rather have it in C++, but they aren't a priority.

my bad, i guess i can just rewrite it
void swap(void* x1, void* x2)
{
void* temp = x1;
x1 = x2;
x2 = temp;
}

This doesn't technically swap the value but it still get the job done depending on what you want to do

What's the recommended programming language for beginners? Looking to learn a bit of this stuff as a fun side-hobby. I've heard Python is a decent entry point, so I think I'll try that.

c

this is all kinds of broken

Python then C.

As long as you're using gcc or clang, this should work
#define SWAP(x, y) do { __auto_type tmp = x; x = y; y = tmp; } while (0)

how does it make it easier?

The stack is in memory and the program keeps track of how to access memory based on offsets of the stack pointer, which may or may not be automatically incremented by the CPU.

Registers are part of the CPU that actually use the data loaded from memory. ie, to add two values from memory, in registers, you would load them with an instruction with their address and size, then execute an instruction on those registers which stores the result somewhere.

I think a memory controller that can execute instructions on memory directly, would be a major improvement.

resources? advice ? I need help to get started

Thanks user

>What are you working on Jow Forums?

I made a logo today for my new invention.

Attached: floatingelectricity_logo_v2.png (900x900, 110K)

i should give up programming...i cant even turn on python without getting confused...i wanna make a vn tho i hate my low iq self

>I think a memory controller that can execute instructions on memory directly, would be a major improvement.
Fucking genius!! 5x times slower PC when?

I like the concept, but I tihnk just having one of them, and a smaller logo, might be cooler.

Just use one of the probably several vn game making engines that exist to make money off impressionable weeaboos like you

Everything about this is wrong, I don't feel like teaching you the C programming language but I think you have the right to know that you need to read a book, fast.

Attached: 1349909715063.jpg (566x480, 65K)

i should kill myself