/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1525199197873.jpg (500x573, 49K)

Other urls found in this thread:

git-man-page-generator.lokaltog.net/
en.cppreference.com/w/c/io/fscanf
stackoverflow.com/questions/16883037/remove-secure-warnings-crt-secure-no-warnings-from-projects-by-default-in-vis
twitter.com/NSFWRedditVideo

First for fuck anime.

Second for fuck anime.

Third for fuck anime.

Fourth for fuck anime.

f u c k
o *> o *> p

Fifth for fuck anime.

you already have a reddit shitpost thread, fuck off back there retards

Attached: 1549682670729.jpg (164x200, 13K)

algol 68 compiler when

This is why you #include the libc

You have your retarded crap board

How do you find time to learn all 300,000 git commands? I can't even remember more than five or so commands.

You don't need most of those, just read the got tutorial.

Man fuck it, I'm using GitHub Desktop

Just learn fetch, merge, rebase, add, commit, push, and in 1% of the cases where those don't cut it just look up whatever you need to do and copy the first post from StackOverflow.

also reset, cherry-pick, remote, pull, checkout, branch, stash, rm, diff

diff, checkout and branch might be useful too

Don't forget to bless.

init and clone

I use reparameterization of homomorphisms every day though. There are just too many useful git commands like that.

Just read the docs bro: git-man-page-generator.lokaltog.net/

Thanks! I was trying to look up the documentation for git ransack-tip. No websites are hosting the documentation due to server limits.

What's the fastest way to sum up bytes in 256-bit vector registers? Say I have 16 registers or something.
I know I start with _mm256_sad_epu8, but what then? shift + or, and then hadd? Or do you do something like shift and add with mask?

Attached: 1529977815916.jpg (804x802, 85K)

Makefile

Attached: githubmake.png (2560x1309, 147K)

I use git every day. The most frequent commands I use are fetch, merge, push, add, commit, checkout, stash, and log. Stash is very handy and you should use it. Outside of those commands, just google it, don't waste your time or energy trying to memorize and "learn" commands that you will only need occasionally. If you use them often enough to make it not a waste of time or energy, you'll have already learned by doing anyway.

Here's mine for F#:


It's a bit complicated because it supports compiling to all platforms, x86/x64, in debug and release mode.

Doesn't that $(foreach ... $(CC)) make it so that if you update a single file everything needs to rebuilt?

Hmm, good question. I'll change it later if it causes problems.

>It's impossible to get the physical address of anything on 32-bit x86
What the fuck?

>Strangely, there is no way to access a known physical address. Previously, you could divine the location of an instruction or data value by examining its segment and offset registers. Now, those values tell you nothing about where something is actually located in memory. Even the compiler doesn't know the relationship between a segment value and an actual address. Segment addresses are resolved by the chip itself, not by software. To figure out an actual physical address, you'd have to deconstruct the GDT at run time, teasing the values out of the appropriate segment descriptors.

This leads us to a subtler problem—where do you look? The GDT is just a garden-variety table in memory, but you'd have to know where in memory to find it. The GDTR holds its base address, so that's a start (assuming you can access the GDTR, which is a privileged operation). But what data segment do you use to access the table itself? Even if you know the GDT's base address, you don't know what data segment—if any—covers that area of memory. It's entirely possible that no data segment covers the area where the GDT resides. Unless there is such a data segment, there's no way to read the GDT as data; it's off limits. And even if there were an appropriate data segment, how would you know what its segment index was? In other words, what value should you load into the DS register to access the right data segment?

This highlights still another peculiarity of the x86 in protected mode. Segment registers are now effectively keys that unlock various area of memory. With the right key, you can execute code from a code segment or read (and possibly write) data to/from a data segment. But without the key, you have no idea what code or data segments might be available. You can't just experiment with different segment values, either, since almost all undefined values will cause a processor fault.

can someone suggest a java book that goes a little in depth and explains a little about what's going on under the hood?

this makefile is shit
it forces recompiling every object file every time one of them changes
the whole point of make was avoiding that and only needing to re-compile those files which change
but on the other hand it's C so unless it's a ridiculous FUCKHUEG project it still probably compiles in 0.001 seconds

first learn assembly then read read K&R C

I don't plan to make it a large project, but if things are annoying, I can probably remove the foreach, and add OBJECTS to the all line, and then chance the foreach to be a singular version of the compile command. That might fix it, but I'd need to do the exe only after all those.

Just find a good video and documentation on the JVM byte code.

And something on its garbage collection algorithm (really don't need much to understand this).

They're both really not that complicated. I don't know if you need a whole book unless you want to dig into how compilers translate Java language concepts into bytecode. JVM bytecode is pretty close to pure machine code only with a lot of extra info for the sake of reflection. And the Garbage Collection structure is basically one big tree.

I don't know if you know how make works user:

You primarily define *target files*, along with the files they depend on, with a recipe to make that one file specifically
then make only runs the recipe to re-create the file when one of its dependencies has changed
(dependencies are the targets or files you list to the right of the colon)

in your case the final exe depends on all the objects and its recipe is the linker command, whle each object depends on its own c file and its recipe is the compiler command

if you have one recipe to re-make an object from the relevant C file, then make will know to only re-build those objects whose last-modified date is less recent than their C file's last-modified date
then, since an object was modified, and you've listed it as a dependence of the executable, make will know to re-link the executable

opaque structs piss me off

I don't know shit about using make, are you too dumb to tell?

Attached: I+made+this+_31fb7da54539d1ddd29a71fd2455e9d5.jpg (254x223, 13K)

Why? They make perfect sense, and allow for type-checking on data you otherwise can't access.
Now when someone uses a void * for that purpose, that's really fucking annoying.

I know, I know.
They just piss me off.
I honestly don't know why.

>compiles in 0.001 seconds
not with the header crap. Even java can do better compilation times for both simple and large programs (unless you use the dumpster fire known as jne)

Why won't my EOF loop work? I just want my loop to scan through the file and increment my count variable till the EOF is reached.


int main()
{
int count = 0, temp;


FILE*infile = fopen("intfile.txt", "r");

while (fscanf(infile, "%d", &temp) != EOF)
{
++count;

}
printf("count size: %d", count);


fclose(infile);

system("pause");
return 0;
}

yeah maybe later though
sounds like what i need. i am going through the basics again as well. thanks for the detailed reply.

to be specific here, your rules should look like this

all: $(BINNAME)

# this rule tells make how to produce the executable file. it will run it whenever something in $(OBJECTS) is more recently modified than the binary file
$(BINNAME): $(OBJECTS)
$(CC) -o binname etc

# this rule tells make how to produce one object file. it will run it when the matching .c file is more recently modified than the .o file
# the % is a wildcard that matches the same value in outfile and dependence
$(ODIR)/%.o : $(SRC)/%.c
# $@ is replaced by the specific target file in the current execution of this recipe (i.e. whatever.o), while $< matches the specific dependency file (whatever.c)
$(CC) -c $< -o $@ plus flags or whatever


note however that this simple solution won't recompile files if a HEADER changes, since they aren't listed as dependencies for the object rule.
there is an -MM flag for gcc which will run the preprocessor and produce a makefile with header-dependency information for the .c file you pass in, and you can have make automatically run this and include the result in the makefile, though if objects go in a separate directory you'll probably need to pull some shell shenanigans and pipe the result through sed

here's part of a makefile i wrote that does just that:

# text-replaces .c to .d
DEPENDENCIES := $(SOURCES:%.c=%.d)
DEPENDENCIES := $(addprefix $(OUTDIR), $(DEPENDENCIES))
HEADERGEN = gcc -MM -E
SEDSCRIPT = sed 's,\(.*\.o\),$(OUTDIR)\1,'

#recipe to create a .d "dependency" file from a c file
$(OUTDIR)%.d : %.c
$(HEADERGEN) $< | $(SEDSCRIPT) - > $@

#make the makefile depend on the .d files, meaning they must be up to date before any other recipes are run
makefile : $(DEPENDENCIES)

# works like C include directive. just a straight copy-paste from file to file
include $(DEPENDENCIES)

check feof().

would, but not allowed to use that, assignment says I have to use use fscanf to determine the EOF.

honestly i just didn't notice the "copied from stackoverflow" and assumed you had written all that shit yourself

And even if you could read the GDT, you still need to see the page tables as well :)

fscanf's return value is not what you think it is, and it certainly isn't the value of `temp`. (how would that work if you passed multiple variables into it?)
check the "return value" section at en.cppreference.com/w/c/io/fscanf

>not turning paging off

I want to into emacs but at my school i'm going to be doing a lot of programming working on an engine in C++ for a big group project (game) with several other programmers. they're almost certainly going to be using MS Visual Studio
is it reasonable to to stay compatible and ensure I'm compiling with the same settings as the VS project and all that shit if I do this, or should I just suck it up and use visual studio like everyone else?

pic unrelated

Attached: programming socks.jpg (1944x2592, 263K)

Attached: BBXsKV2.jpg (720x960, 104K)

Can't you just edit in emacs and then compile it using Visual Studio's tools? In a business situation, there would probably be a lot more resistance to using using tools that cannot be easily integrated into the company's common stack, but in a student situation, I don't think that'd be a huge problem.

At the end of the day it's just text you're writing in folders.

>segfault

void*

(*var).pooinit();

>runtime type safety
>lambdas
>overloading
OI CANT READ THIS, ITS ALL IN FOCKEN FRENCH

It won't compile without this part.
#include

Next time, at least tell us the error message.

that's obviously not the complete file . you are being intentionally retardedly obtuse
(the problem is that it's an infinite loop because her end of file check is wrong)

as said, that wasn't the complete file. I do have stdio.h included.Issue I have no fucking idea how EOF works.

well then you clearly didn't read the post here because it would solve your problem in 2 seconds

No I did read it. It just went over my head and now I'm googling around.

>Return value
>Number of receiving arguments successfully assigned (which may be zero in case a matching failure occurred before the first receiving argument was assigned), or EOF if input failure occurs before the first receiving argument was assigned.
If you inspect your code, maybe add some breakpoints or just print statements for debugging, you'll see that fscanf is returning 0
that means it is finding some text that cannot match "%d" before it reaches the end of file, meaning there is something in that text file other than just numbers that can be converted to ints (perhaps even just decimal points or whitespace)
if scanf fails to match it doesn't advance through the input

you should choose a different format specifier that more accurately does what you want it to

Oh. It worked on my system (arm32 linux) after removing pause. On Linux scanf() returns EOF but I don't know about other platforms.

Ok there is literally something wrong with my computer/visual studio. I just tried running an example code using feof and it didnt work. I just tried copying and pasting code from my program I made yesterday that had a different type of EOF loop and even though it worked yesterday, now it isn't.

This code literally worked yesterday and now it won't:

Header.h:
#include
#include
#include
#include
void chargesfunction(double hours, double *costperhour, double *avgcostperhour);

Source.c
#include "Header.h"


void chargesfunction(double hours, double *costperhour, double *avgcostperhour)
{

if (hours > 10)
{
*costperhour = (hours - 10)*1.99 + 10 * 7.99;
*avgcostperhour = *costperhour / hours;
printf("totalcost: %lf averagecostperhour: %lf\n", *costperhour, *avgcostperhour);


}
else
{
*costperhour = hours * 7.99;
*avgcostperhour = *costperhour / hours;
printf("totalcost: %lf averagecostperhour: %lf\n", *costperhour, *avgcostperhour);

}


}

Main.c:
#include"Header.h"

int main()
{
int day, month, id, i = 1, j = 1;
char c;
double hours_used;
int id_array[10];
double charges_array[10];
double costperhour = 0, averagecostperhour = 0;
//double costperhour, averagecostperhour;

FILE*infile = fopen("usage.txt", "r");
FILE*outfile = fopen("charges.txt", "w");

fscanf(infile, "%d %d", &day, &month);
printf("day: %d month: %d\n", day, month);

while (fscanf(infile, "%d %lf", &id, &hours_used) == 2) {
//fscanf(infile, "%d %lf", &id, &hours_used);
id_array[i] = id;
charges_array[i] = hours_used;
printf("ID: %d hours used: %lf\n", id_array[i], charges_array[i]);
chargesfunction(charges_array[i], &costperhour, &averagecostperhour);


//code that prints charges and id of code
i++;
}


fclose(infile);
fclose(outfile);
system("pause");
return 0;
}

Picture is the screenshot of my usage.txt file along with the warnings im getting.

Attached: Capture.png (1791x898, 45K)

>This code literally worked yesterday and now it won't:

Impossible, you must've changed something or it didn't work in the first place. Computers do exactly what you tell them to.

is visual studio actually compiling your project, or is it failing to compile and then just running the "last successful build" when you hit the run button? because those messages are showing up as warnings rather than errors

its saying there are build errors and asking me if i want to run the last successful build but there isn't one because this is a brand new project.

I literally just opened the the project that I copied this code from and it works without errors or warnings. I copy and paste that same code into a new project and it won't compile.

oh my fucking god you retard did you actually read the error messages describing why it isn't compiling jesus christ
asking for help is fine but asking for help with an error before READING THE FUCKING MESSAGE that's right there on your screen is enormously stupid

git gud

Sure is a nice data stream you have going there, sure would be a shame if someone was to DROP A FEW PACKETS.

Attached: 1441776042541.gif (260x195, 2.44M)

seriously, why the hell isn't simple scanf or fscanf working? I literally don't understand.

Attached: Capture.png (1447x623, 31K)

>Impossible, you must've changed something
It's possible that the compiler (written in a shitlang) depended on some shared mutable state which has now changed.

Why the fuck would you ever use visual studio? It's straight up complaining about something that is completely valid.
Anyway, you probably need to put that #define before you include any headers.

Just use python. Or disable warnings as errors.

There might be a difference in project configuration, but I wouldn't know how to compare the two configurations to be sure.

>not working
READ THE BOTTOM 1/4TH OF YOUR SCREEN AND COMPREHEND THE WORDS
also if actually wasn't compiling instead of giving wrong runtime results you should have said that in the first place instead of asking for help.

I don't get it, what's the question? Assuming AVX2, just _mm256_add_epi8 them.
If you have more than two registers, then add them in parallel so that CPU can dispatch multiple sums at a time. Say, if you have 4 registers, do it like that:
(1+2)+(3+4)
The less data hazards the better.

Okay guys I was trying to compile "cout >> "Hello world";" and Visual Studio says "operator >> not defined in this context, were you thinking of cout

Welcome to the pile of shit known as "C++".

You weren't the first to have this same issue. stackoverflow.com/questions/16883037/remove-secure-warnings-crt-secure-no-warnings-from-projects-by-default-in-vis The error messages help (sometimes).

Good job adapting earlier BTW.

reas a book

> are known as the bit shifting operators. they overloaded for use with the standard streams library. you are using the wrong operator and visual studio is correcting you.

a cli xdcc anime downloader rewrite from js to go

I wrote one of those years ago when I was learning to program, but in C, and not using any external dependencies.
That was some shit code.

Attached: 1543220845606.gif (1050x850, 1.97M)

cout is an "output stream"
in this case specifically, operator> is used to "extract" data from a stream, for example reading from user input and putting the result into a variable

try to do this to see the difference:

string userinput;
cout

I was making fun of the other guy in the thread

oh i forgot to mention that i coupled it with a search function that is configurable over multiple xdcc listings

Cool explanation, I think I will just use printf("", ...) instead.

>I'm retarded so the language is at fault here

My one read nyaa's RSS feeds.

that some serious useful function, i planned to add later on (reading from rss feeds). its currently my pet project to learn go.

Should I learn Go? How can I learn? I am desperate for cash

Thoughts on graphql?

>desperate for cash
>learn go
lmao

Go is like every other language with some retarded stuff on top.

how do you go about rewriting cnile shit into a proper language like c++?

Are you genuinely fucking retarded?

Cut him some slack, he's using VS so at least he's honest about his retardation.

What kinda stuff do you guys really like?
For me it's concurrency, like chat applications and MMOs, or game services. I love that shit.