/dpt/ - Daily Programming Thread

Previous thread: What are you working on, Cred Forums?

Other urls found in this thread:

ecma-international.org/ecma-262/7.0/index.html#sec-toboolean
ecma-international.org/ecma-262/7.0/index.html#sec-logical-not-operator
ecma-international.org/ecma-262/7.0/index.html#sec-abstract-equality-comparison
landinghub.visualstudio.com/visual-cpp-build-tools
buildyourownlisp.com/
tutorialspoint.com/csharp/
plnkr.co/edit/zkrJ5aQ8kf6zyHMKjxBF?p=preview
postgresql.org/docs/9.5/static/functions-aggregate.html
en.wikipedia.org/wiki/Boyer–Moore_string_search_algorithm
swtch.com/~rsc/regexp/regexp1.html
forum.dlang.org/thread/[email protected]?page=1
github.com/salvadorp2001/Little-Man-Computer-CPP
stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work
youtu.be/TH9VCN6UkyQ?t=1784
glad.dav1d.de/
twitter.com/NSFWRedditGif

finished my first C program, you give ti a chess board and it determines the best anithcess move

at first forgot to free memory in the alpha beta search and had to reboot computer because memory ran out

How the fuck does ipv4 work?
Seriously who invented this autism

>write C
>make mistake
>shutdown computer

?

THE MEMORY'S ALL FUCKED NOW

he's obviously writing a bootloader

What ancient piece of shit OS are you using?

>not installing Gentoo into ram and having to reinstall everytime something overflows
SHIGGY DIGGY

>write C
>confuse "if (c == true)" with "if (c)"
>delete filesystem

Do you even know how computers fucking work?

Do you?

I literally have built computers in minecraft
Watch who youre talking to kiddo

There's no true in C unless you use some shitty header like stdbool.h but then that's your own fucking fault.

c

>shitty
>C standard
pick both and only both

Well apparently you don't because you don't understand something as simple as paging and memory protection.
It doesn't fucking matter if you installed Gentoo on a RAM disk, a segfault is only going to potentially fuck up the address space of the process that caused the segfault, which is gone now because the kernel killed it.

What if a have a really early version of Gentoo without proctection though?

It's a behavior that is well defined by the language specification and actually does make sense.

Please see
ecma-international.org/ecma-262/7.0/index.html#sec-toboolean
and
ecma-international.org/ecma-262/7.0/index.html#sec-logical-not-operator
and
ecma-international.org/ecma-262/7.0/index.html#sec-abstract-equality-comparison

Don't try to badmouth Javascript when it's obvious that you never read anything about PLT.

I'm being rused now aren't I.

>putting an OS into your drive without using protection
your computer is a slut

>I literally have built computers in minecraft
>Watch who youre talking to kiddo
hmm

?
It's entirely possible to build computers in minecraft using redstone.

Could we make a compiler that compiles code to redstone?

Minecraft computers don't deal with paging and virtual memory addresses, so that explains why you don't know how it works. Please don't act like a fool though by saying that you know everything because you built an APU in Minecraft.

Could we in the esteemed company of...

The Great Autismo??

you fucking manchild

If you reverse engineered the format minecraft maps are stored in, then I don't see why we couldn't.

spending 2 weeks with a language just to check out its basic syntax and practices gave some insight as to why for example C# does some stuff that it does.

You obviously can't learn 6 languages in one year. Well actually by know I'd say I don't really look at programming as "Learning C#" or "Learning X language" anymore. Its more about just practicing doing stuff.

I'm only a year in right now but the most valuable part of learning the syntax of a language is being able to read more types of code to see what people are doing.

Then again I'm just some shitter that wants to make games and is currently working on the meme of making my own terminal game engine so I can make hipster modern-esc UI within the terminal. I'm working on adding dropdown menus.

Yes I know and that wasnt a lie pic related
But they cant get complicated enough to have memory protection, paging etc.
So the whole thing was supposed to sound like someone talking out of his ass

>2016
>he hasn't rewrote the TempleOS kernel in NAND gates
get out kiddo

Don't just go assuming things.
Of course I have.

Redstone can make NAND gates, which means that a redstone computer can be turing complete.

Is it possible to download just the Visual Studio compiler without the shitty IDE.

Yeah but minecraft is a piece of shit written in awful java code
The game afaik stops processing redstone past a certain range and starts lagging super hard

That was supposed to be a ? not a .

why not just use the GCC? and yes you can from here landinghub.visualstudio.com/visual-cpp-build-tools

Redstone is turing complete
The VM it runs in (Minecraft) just isn't able to process it when the contraptions get big enough.

Which one?

Yeah, they're called Visual Studio build tools. Alternatively, you can use MSYS2 to get GCC.

Yes I know thats exactly what I was talking about
Someone building a computer in minecraft couldnt possibly have implemented paging and memory protection

turing complete doesn't mean what you think.

Can someone post the latest programming challenges picture?

Could you please pinpoint the mistake I made in my replies?

Lads I have a domain name, weeaboo.net coming up for renewal.

Do you think it's worth renewing or should I just give it up since I don't use it?

0:30: Trying to find a way to bind $scope variables to the template...

Most I can write in is commandline lol

Not sure if it's the latest but here is one

0:33 Dumping challenges for user instead of figuring out binding.

0:34 - realizing user already posted an updated version

I own a bunch of stupid domain names and renew them, and you should too. Maybe we can have a stupid domain name party.

is that the indian version of fizzbuzz?

Ty senpai

ive done majority of these and can do vast majority of these, the rest id have to read about

am i programmer

no

you need a programming license

what

Using Game Maker Studio. This is programming, hopefully one of you here have experience with GameMaker.

I want to draw a view (as a surface) onto another view, and draw stuff on the latter view as well. I am making this game with iOS in mind.

Pic related is what I am getting, I think I am close, but not entirely there.

I made an object called game_draw, and on the create event:
surf = -1;

scale_ios = 3;

if !surface_exists(surf)
{
surf = surface_create(view_wview[0], view_hview[0]);
view_surface_id[0] = surf;
}
on the end step event: (this is the only way the camera will work for me at the moment)
/* center the camera on the player */
view_xview[0] = -(view_wview[0]/2) + objPlayer.x;
view_yview[0] = -(view_hview[0]/2) + objPlayer.y;

/* so that the camera works */
view_xview[1] = view_xview[0];
view_yview[1] = view_yview[0];
on the draw begin event:
if view_current = 0
{
if surface_exists(surf)
{
surface_set_target(surf);
}
}
on the draw end event:
if view_current = 1
{
surface_reset_target();

game_w = view_wview[0] * scale_ios;
game_h = view_hview[0] * scale_ios;
game_x = display_get_gui_width()/2 - game_w/2;
game_y = 0;

if surface_exists(surf)
{
draw_surface_stretched(surf, game_x, game_y, game_w, game_h);
}
}

I do not think I am doing things correctly, and I tried drawing something onto view 1 (the larger view) and it didn't show, but if I put it somewhere like 0,0 then it shows up in view 0 (the smaller view you see the game on right now) scaled.

Any ideas?

>Not having the official Oracle™ Java™ Programmer license

>he forgot to collect his programming license
bahaha enjoy doing CS again from the beginning

Yes. But why would you? The IDE is the best part of MSVS.

>Using Game Maker Studio.

the tag doesn't exist there

>Using a computer with a operating system pre-installed instead of writing your own

kys

ive been meaning to ask something connected to what this guy is askingif you dont really need an entire game maker studio, do you just use a gui window and fill it with the functionality you need to make such games?

or do you use some other type of window?

>rolling your own crypto

>it does actually make sense when you learn a giant table by heart
no
we know that it isn't arbitrary
we know that it's well specified
it's still shit

>That feel when they tried to ceremonially give me my programming license before i was formally done with my education, so i didn't attend the ceremony so they threw it away and now i'm done i can't collect it.

>Not building your own computer
>>>v

works for me, search for agdg yourself then.

>kys
/agdg/ has a lot more people with experience in game maker studio, thats why I send him there.
Are you so retarded that you just imply every cross-board link is an insult?

Are there any printable characters that get sorted after all the alphanumeric?

I need something to tag a few files to make them appear grouped at the bottom of the file list.

>3GB for a sub-par compiler
What the FUCK does Visual CPP Build Tools come with? It's literally just the compiler and it's bigger than an Arch Linux installation with GUI and gcc

well theoretically redstone can be used to simulate a turing machine and can kind of be seen as a "set of data manipulation rules" if you take the mental gymnastics far enough

>every cross-board link is an insult?
To be fair, this IS Cred Forums.

>/agdg/ has a lot more people with experience in game maker studio
I see what you did there

thanks for the heads up

make an array containing printable characters
sort it
find out

You could prefix them all with ZZZ or some shit

0:55 Manged to bind a single variable to scope. Apparently:

public fooNum: number = 42;

is valid syntax for binding properties to the template. Everything said use "this", and now it doesn't seem to work. Much confuse, wow. Next step - bind object to template and get props / run methods on event.

It does make sense if you have a minimum of PLT knowledge.

Boolean("0") returning false would only make sense if the semantics would be the same as Boolean(Number("0")) but that would be completely retarded since a string can be empty and doesn't necessary represent a number (what about Boolean(Number("Java")) )

Renew it, or at least sell it. It sounds like it could be worth something, as far as domain names go.

It makes sense, but it still leads to highly unintuitive looking code and bugs. Thats why it's shit.

pic isn;t good simply because it's in the spec.

OK, please advise me on how best to go about this:

>Learnt C at Uni. Pretty good at it.
>Learnt Java at Uni, basics at most. Not great with OO
>Want to learn iOS/Android dev

I keep starting then stopping tutorials. I got fairly far through some iOS ones, but then real life stopped me and now its been a few months.

What should I do? Should I read K&R to restart learning my C as its been a few years since I've seriously done it.

Or should I focus on learning OO in some way?

I should I just focus on the iOS tutorials and take that steep learning curve?

what?

Do any of you know any book/course on C++ similar to "Learn C the hard way" or buildyourownlisp.com/ ?

torrent/download link for K&R? Not a noob, but not programmed in C for at least 18 months now

I finally managed to figure out the stupid Angular2/Typescript syntax for binding actual objects to scope:

export class SimpleComponent {

public fooNumber: number = 5;
public user: Person = new Person(1, 'user');

}

export class Person {

id: number;
name: string;

constructor(id: number, name:string){
this.id = id;
this.name = name;
}

}


wew lad, learning web libraries can really cause an existential crisis

>Not great with OO
>Or should I focus on learning OO in some way?

OO is trash

>01:36*

Well please advise me on how best to work towards my goal of app development

?

Just learn objective-C and iOS SDK and Java and Android SDK respectively.

Don't listen to that faggot. If you want a job and you aren't an absolutely genius, learn C# or Java, preferably C#.

I am: P.S. Even front end/mobile is going OO now. Code snippet very related.

>hasn't rewrote
*rewritten :^)))))))))

The market is narrow for C# mobile app development.

Though Xamarin is based af

I have a job already. But want to learn this in my spare time.

There is thoughts that work are going to send us on a C# training course soon, to standardise the way all our tools are written. So would prefer to not learn that for now.

How would you suggest i learn OO? Is there a good guide or something to work through?

>"0" equal to false
>acts like true on conditional expressions

Most large companies use C#/Java in general. Xamarin IS awesome, especially now that Microsoft bought it and made it free.

I don't know of any AMAZING books desu. I read "C# in a Nutshell, the Definitive Reference". Honestly, just go through something like this first though:

tutorialspoint.com/csharp/

it should be a breeze, but will give you a basis.

P.S. I know you asked about Java, but I don't know it (in fact, had to try very hard to avoid it recently).

That has led directly to some hellish bugs in days gone by... Fuck JS. Fuck people who think weak/dynamic typing is ever a fucking good idea.

Why do so many engineers prefer Ruby to Python?

I mainly use python (Data analyst), but from the little bit of ruby I've dealt with, it seems a lot more cluttered than python, and a bit less intuitive.

What's the reason it tends to be preferred?

Yeah, but few use Xamarin for app development compared to Objective-C/Java.

Swift is the future user. Put down Objective-C.

Yes, it's the future. Not the present. Have fun getting an iOS job with only Swift and not knowing Objective-C well.

Stop making shit up guys, you are as bad as the OO user. Proofs:

plnkr.co/edit/zkrJ5aQ8kf6zyHMKjxBF?p=preview

if (0 || callAnonAFag() ){}

Obviously it acts FALSY.

I am: 01:50: Arguing with faggots instead of studying.

As far as I know, that's true, so no arguments there.

>Why do so many engineers prefer Ruby to Python?
Because they're gay.

DESU, I really can't imagine me learning Objective-C (or even Swift for that matter) to a high enough standard to get a real job with it.

I expect to make a few apps for myself and have a small portfolio, and then use that to get contract jobs from the likes of freelance websites, rather than corporates.

>It's a "I overload operator() to do everything" codebase

>to a high enough standard to get a real job with it.
It's really not that hard. Most iOS dev's are horrifyingly shit. People often think programmers jobs must be these amazing professionals, but most of them aren't. Their mostly glorified script kiddies who think they must be experts because of their paychecks.

I want to know 2 file locations which I don't want to pass to my program every time I run it.
I keep the paths in a file that its path I #define and it does what i want but it feels very shitty way.
Basically, is there a way to keep the location known to a program after it has shutdown and rerun without passing it every time (pass once and keep until it's changed) and without being specified at compile time.
I'm using c.

post code

paths.txt

>Their mostly glorified script kiddies who think they must be experts because of their paychecks.

Trips of truth despite
>their

Well, I can do my best and learn hard. For me I'll be learning Swift. If that rules me out of iOS dev jobs from a corporate point of view, so be it.

I didn't get the stuff I was learning about MVC and MVVM (same thing?), so really struggling. That's why I was wondering if it was worth learning OO first, before jumping into stuff about Swift.

Yes, thats what I do but the path of the paths.txt is still a #define. Btw i don't want it to be in the current directory, I want it to be able to be anywhere

The more i think of what i want to do the more I think its not possible.
In other words i want to do this:

int defaultvalue=1

changeDefaultValue(int x){
defaultvalue=x // i want this to carry over to the next time the program is run, so i want x to be the value of the defaultvalue the next time it is run
}

its stupid.

a #define or an argument pass*

>I didn't get the stuff I was learning about MVC and MVVM (same thing?), so really struggling
You may be shocked to find how few devs really understand MVC in the industry. Infact, it's not really that clearly defined in my experience. People seem to have different definitions of it that they accept. MVVM is more clearly defined though. Not too important for iOS dev though.

Swift is OO. It's basically Objective-C with a lot more static typing, better syntax, random things fixed and more functional language features.

You don't.
Even the very first publicly released Linux (0.1) had paging.

>not mining and refining the minerals yourself

I guess I should just go with a certain location like programs do with their config files...

Yes.
Get the WinDDK (for Win7 and earlier) so you can also link against msvcrt.dll and not have to worry about vcredist bloat.
(Still a ~2GB install though)

just do what werks and is simplest

What is that pic saying? C++ is lazy bitch who dreams of doing everything but wont get of her lazy butt to do anything, while C is perfect waifu?

I'll just put the "paths.txt" in a certain location(it can be the home directory which is easily identifiable in any machine) and I will read/modify the paths(the files can be anywhere) when i need too. I guess that's a good way to do it but initially i thought i could have that "paths.txt" anywhere I wanted.
Putting the files in the same directory as the program is being run into would work too put it would be complete fucking shit. I'm looking to find a good way more than making it work, because to make it work is not a problem.

OK, so what book/tutorials/whatever is good for learning OO?

Otherwise I'll brush up on my old C with K&R first

>work too put it would be
but*

2d game in UART with ARM64 assembly
Trying to get the poo emoji work on sakura

wait why cant you just do directory1/directory2/paths.txt

SQL noob here. If I have a table like

student_id | score
1 | 90
1 | 100
2 | 90
2 | 0
2 | 0

how do I find the average score of each student like so:

student_id | average_score
1 | 95
2 | 30

Are you trying to do a chris sawyer?

>I don't google it every time I have to do it at work

updating index?

im making a game where ur pajeet and u must escape evil white men who try to erase ur identity and make u poo in loo

Is this an array or a list? I'm a little confused.

#Python shit
MyThing = []
MyThing.append("thingy")
print(MyThing)
#it's gonna print ['thingy']

Now that you mentioning it i can get the full path of the executable from argv[0], maybe i should just go with ./paths.txt. I didn't want it to be in the directory of the program or being associated with its directory because I thought that if the program would be called from another location i wouldn't be able to find the paths.txt.

it's a list but the python standard calls them arrays

>run "appbuilder build android"
>browser tab with login form opens up
you gotta be shitting me

the reference assemblies for framework .netframework version=v4.5

How do I fix this, I have .Net 4.5 installed. I'm using Xamarin Studio Community on windows 10.

It's in the same principle, you specify a certain location. In the first idea you specify the home directory (or the /etc/ directory) which there are in every machine and in the second you specify the folder of the executable. I think I got to the bottom of this and I have the understanding of how to avoid the file not being found-able.

>02:38
>going to write a service and wrap it up

What's the difference between an array and a list? I don't understand.

A list is generally variable length. An array is a fixed length in many languages. Somehow, this makes it faster to loop over. Also, lists are generally easier to work with, exposing foreach loops and such. Arrays generally want basic for loops.

>02:41
>still shitposting

>Somehow, this makes it faster to loop over
no, this is only true for linked lists (not for array lists)
the foreach example is pointless and only true for languages like java

I am not going to argue with you, since I only know examples from specific languages.

I'm writing a sample web application in Scala for work to convince them to rewrite this main web application in it.

I really like Scala and SBT too so it won't be too bad if they don't want to use it.

You'll probably have to group by student_id and then some sort of aggregator for the group of values.

postgresql.org/docs/9.5/static/functions-aggregate.html

Arrays and vectors are faster to iterate than a linked list because their memory is contiguous and good for the CPU cache.

What does an array look like compared to my "thingy" list example of appending that String to the list?

you cannot append to an array
an array has a fixed size

So I've graduated and I actually need to find a job, I only did one unit on Java and hardly paid any attention but I have to learn that shit to pass a programming aptitude test on Tuesday. Is Java, A Beginner's Guide the best place to go to cram as much in as possible by then? I've used a bunch of other languages (including oo) so I'm no stranger to programming logic I just need to learn how to do it in Java.

hey guys rate my python
def bootstrap( config:Union[
str,
dict,
os._Environ
] = os.environ ) -> Callable[
[
Union[ Iterable[ str ], Service ],
serve.Verb,
str,
Optional[ bytes ]
],
Optional[ bytes ]
]:
"""Bootstrap the Gumballs environment
Args:

What do you know, most of the syntax can be assumed from other langauges, but the specifics might get you.
So id skip the beginning of any book to get to the language specific info.

I've completed a comp eng degree so my programming base is decent, mostly from C and Python. I probably just need to drill in any Java-specific terms and class structure. It's online and open book so I don't need to memorize it or anything, just not be completely stumped when I start.

>online and open book.
would any company take this seriously?
completely cheatable.

I started C after java and every rule that applied in java applied in C.
But your problem is, C is simpler than java so you gotta get a grips on OOP.

They claim their system can tell if you cheat, presumably by comparing your code to the database of other completed solutions. No idea how well that system works. I completed a year-long placement writing OOP Python so that shouldn't be too bad either.

How obscure are regular expressions? I know they're usually avoided unless you really need them, but I'm curious how often they actually come up in production

Regular expressions aren't obscure at all.
>I know they're usually avoided unless you really need them
Why would you avoid them? You just shouldn't try to parse non-regular grammars with them (e.g. bracket matching) and you shouldn't to simple substring searches with them (because more efficient algorithms exist for that).

>substring search
Who would do this with anything other than a FSM?

python sucks desu

Why wouldn't you use KMP?

>simple substring searches ...more efficient algorithms for that
example?

I was taught Robin-Karp

en.wikipedia.org/wiki/Boyer–Moore_string_search_algorithm

I wonder why all this stuff I read said to avoid them. I figured they would be very useful, that's why I asked.

just consider this
swtch.com/~rsc/regexp/regexp1.html
most regex implementations are shit and dangerous
stackoverflow recently had a long downtime because of this

Robin-Karp also works.

I don't use them much in production code, but I use them all the time to write little convenience scripts and find things in the fuckhuge legacy codebase.

We can thank the idiots who disregard computer science theory for that.
Larry Wall is a hack.

im a hack :/

Perl made web programming easy, though. It ushered in this wonderful age of web applications!

so did php

Yes, and PHP is excellent, too.

not funny

comedy requires more than just tragedy to be funny

Trying to learn OpenGL to "graduate" from command-line applications.

I'm starting to read the "OpenGL SuperBible", and I notice that it's focused on OpenGL for Windows. If I'm using XCode on a Mac, would the sample code still work?

>"graduate" from command-line applications
But CLI programs are arguably the most useful.

But I want to draw Conway's Game of Life on a pretty window and make ray tracers, user!

Unknowingly, I answered my own question.
The "readme" on the source code tells me to use Cmake. (Specifically, cmake -G "unix Makefiles")

He means toy calculators or whatever

forum.dlang.org/thread/[email protected]?page=1

>removing semicolons this late into a language's development

Likely the most powerful, too.

Opengl is portable, windowing and context creation is not.
Use SDL or GLFW for those.

So this might sound crazy, but on VS 15 Preview 4, hitting the "start" button doesn't actually start debugging. It'll just flash once (the debug process presumably gets killed) and then it'll just refocus on the editor. It's not doing this every time, either.

It's pissing me the fuck off.

Anybody have a clue?

Is this my IDE telling me my method name is stupid?

Whoops that shouldnt be private.

VS is literally getting worse every update.

All other IDEs suck, expect for Jetbrain IDEs but CLion isn't free.

Install Gentoo
Install emacs
Have fun

vim > emacs

from head to toe

It is if you're a student. It's the best.

I don't want to do that.

I'm implementing Little Man Computer but with the accumulator and program counter as objects just to learn a bit of OOP. How retarded am I?

It could be worse.

>It is if you're a student
No NEET licenses I'm guessing.

Not that I know of, no. That said, you could buy it with your NEETbux.

You can do without, but if you want to practice OOP I don't see the issue.

Why is Pearson so amazing? Why are they literally the best publishers to ever publish computer science textbooks? I love Pearson, thanks Pearson!

do we prefer vc++ or gcc++

That will prepare you well for how OOP is used in the real world.

Neither, because C++ is shit.

idiot

Get some taste, fag.

your right

*installs rust*

heh... gonna make it now...

>*emotes*
I think you should leave.

psht...

nothing personnel kid...

I wanted to answer someone in a thread, but the thread got deleted, so I'll post the code here anyway. How would you improve it, /dpt/?

Here's the problem
>user entres a positive interger
>add up all the number up to this number
>but dont add any number that is a multiple of any of the digits in the number

#include
#include

int main()
{
int number; //number
int n=0; //amount of digits
int *a; //array of digits
long sum = 0; //sum

puts("Enter a positive integer\n");
scanf("%d", &number);

a = (int *)malloc(sizeof(int));

for (int i = number; i > 0; i /= 10) {
n++;
a = (int *)realloc(a, n*sizeof(int));

a[n - 1] = i;
if (n > 1) {
a[n - 2] = a[n - 2] - a[n - 1] * 10;
}
}

int condition;
for (int i = 0; i < number; i++) {
condition = 1;
for (int j = 0; j < n; j++) {
if (a[j] == 0) {
if (i % 10 == 0) {
condition = 0;
}
}
else if (i % a[j] == 0) {
condition = 0;
}
}

if (condition) {
sum += i;
}
}

printf("\n%d\n", sum);

free(a);

getchar();
getchar();
return 0;
}

Just tell it to me straight. How shit is my code?
github.com/salvadorp2001/Little-Man-Computer-CPP

I asked a question about which lang is more hipsterish, Go vs Node.js, and people here said Go.
but, how is it hipster to select a language because of its good perfomance (and resource management) and ease of use? that's what attracted me to Go, at least...

>doesn't even compile LMC assembly
It's shit

Just finished an implementation of Conway's Game of Life in CLI in C++.

How would I make a graphical implementation now that I have the logic of the program?

port it to piet

It's the numeric one. I'm not gonna waste my time separating the mnemonics.

note that the sum of 1 to n of all integers which are a multiple of k is the k*sum of 1 to floor(n/k), hence you can do this in time which is logarithmic w.r.t to n

ill post a solution soon

km(m+1)/2
where m = floor (n/k)

congrats you can repost what someone else said with different wording

Now with excessive error checking and excessive input validation.
#include
#include
#include
#include
#include
#include

int main()
{
long n;
long sum = 0;
bool digits[10] = {0};

char buffer[32];
char *endptr;

puts("Enter a positive integer\n");
fgets(buffer, sizeof buffer, stdin);

errno = 0;
n = strtol(buffer, &endptr, 10);
if (endptr == buffer || n < 0 || endptr[strspn(endptr, " \t\v\r\n")] != '\0') {
puts("Not a positive integer");
return 1;
} else if (errno == ERANGE) {
puts("Integer is too large");;
return 1;
}

for (int i = n; i > 0; i /= 10)
digits[i % 10] = true;

for (int i = 0; i < n; ++i) {
bool cond = true;

for (int j = 1; j < 10; ++j)
if (digits[j] && i % j == 0) {
cond = false;
break;
}

if (cond) {
if (LONG_MAX - i > sum) {
puts("Integer overflow");
return 1;
}

sum += i;
}
}

printf("\n%ld\n", sum);
}

oops.

Truly this is how it was meant to be done.

I think any decent language should manage this. Because comparisons to true can be made into inverse comparisons to false.
Using true as a value? Well you shouldn't, should be undefined.

here.
#include

int main()
{
bool hasDigit[10]; // just ignore indices 0,1
unsigned n, sum;
printf("Enter a positive number: ");
scanf("%d", &n);
unsigned temp = n;
for(unsigned i = 0; i < 10; ++i){
hasDigit[i] = false;
}
while(temp){
hasDigit[temp%10] = true;
temp /= 10;
}
// if we subtract this digit, all multiples have already been subtracted
for(unsigned i = 2; i < 5; ++i){
if(hasDigit[i]){
for(unsigned j = i

You could have just installed Gentoo

Neither should be allowed by the type system.

>#include

I'm sure your parents are really proud of you. What isn't there to be proud of? An autist whos incapable of socializing, undeserving of being loved by anyone, and so he substitutes it with childrens cartoons for love and lust.

You're a real winner buddy. End yourself.

please tell me that this is a pasta and you didn't write this yourself

Why are you even here?

This is more fun. BGI is great.

user please be more friendly.

nice. what is the purpose of the bit shifts?

> for(unsigned j = i

>i*(n/i)*((n/i)+1)
Isn't this just
>n*((n/i)+1)

I assume he's one of -those- types who thinks he always needs to replace /2 and *2 with shifts

iff n%i == 0, then its equivalent. otherwise, the integer division rounds down

just division/multiplication. desu you can safely replace it with the respective div/mult operations b/c any decent compiler will do a strength reduction

>b/c any decent compiler will do a strength reduction
>I assume he's one of -those- types who thinks he always needs to replace /2 and *2 with shifts
Why? It's only potentially slower on modern CPU's?
Am I missing something here?

youre right, using * or / is only potentially slower on modern cpus when compared to a shift op. its not a point people really care about because modern compilers will almost, if not always, reduce it to a shift op.

desu i think hes just getting autistic over it, but autists gonna autist

I forgot to write one information:
>if the digit is 0, dont add any number that is a multiple of 10.

I guess it could be done like this, right?

bool hasDigit[11];

// [...]

if (hasDigit[0]) hasDigit[10]=true;

// if we subtract this digit, all multiples have already been subtracted
for(unsigned i = 2; i

>using * or / is only potentially slower on modern cpus when compared to a shift op.
That's not what I said.
The throughput is lower but the latency is 0.5 on sandybridge for instance compared to an integer mul or div which is higher throughput but 1 latency.
Meaning it's (shift) slower (since a result can't be recieved in half a cycle).

I don't get how someone could conclude that a shift would be faster from that.
And if compilers make that conversion all the time and not just for funsies when it doesn't matter then that's horrible. Now I have to look at all my muls and divs user. Thanks -.-

>imperative

Well there's no fast functional alternatives user.

>if the digit is 0, dont add any number that is a multiple of 10.
If thats the case, all you need to do is add this.
// .....
sum = n*(n+1)/2;
if(hasDigit[0]){
sum -= 10*((n/10)*((n/10)+1))/2;
}
for(unsigned i = 2; i < 10; ++i){
if(hasDigit[i]){
sum -= (i*(n/i)*((n/i)+1));
}
}
// ...

Oops, forgot. change the
if(hasDigit[0]) to if(hasDigit[0] && !hasDigit[5])

and the
&& !hasDigit[2]

o yeah. that too

Hmm so there's actually people who think shifts would be faster than muls and there was any appreciable amount of time where compilers were so crappy that you had to replace it?

Is this like that i++ vs ++i bullshit?

It's like some people don't even write software for computers anymore.

i + 1

Windows 98 & BGI are so much fun. I'm actually enjoying fucking around.

BGI?

Borland Graphics Interface, which they included with turbo C.

>turbo C
>turbo
sounds like a 90s thing

I just dick around with /dev/fb0.

Wow rude mods, deleting that gCPU thread.

I'm a Windows fag. :^)

Some more fun.

who /botnet/ here

I haven't installed W10 yet, but I'm upgrading soon, and I'll have to.

I'll regret it.

>I'll have to
>I'll regret it
Don't do it.

Isn't free time over?

Are you actually paying for it?

>captcha is LITERALLY 2016

>objective-C

fuck that gross shit, use Swift

what should I learn to make gaems? c# or c++?

Unity uses c#

Swift is a troll language.

I don't want to use an engine. I want to draw pixels directly on the screen.

Don't forget what to do on November 8th.

g++ or clang++. Never VC++

then c++

I like the inline assembly better in VC++. : \

Whats wrong with VC++?

C++ is the traditional language for low level engine stuff. If you go that route you'll probably want to go with sdl2 or sfml using opengl for actually drawing.

If you go with C# you can also use sfml.net and opentk for drawing.

we know you are a fag, no need to remind us
fag

in all other respects, I am completely heterosexual.

I think you mean C.
Practically all OS interfaces are in C.

gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);

I dunno what to do about the fact that this gives me "undefined reference to 'gladLoadGLLoader' "

Probably link to GLAD.

What, like include it?

Linking improperly would give him a linker error.
Usually you have to set certain flags before including the glad header. Or you just forgot to include it altogether.

Setting flags before including a header?
Weird.
I'd certainly have no clue what to do there.

>set certain flags
Sorry I mean set defines.

Throwing my vote away and voting for the Libertarian candidate, because not knowing what Aleppo is pales in comparison to how horrible the other two candidates are?

If you learn c++ you get c for free.

absolutely nothing

No you don't. And you get a ton of useless knowledge that confuses you.
gladLoadGLLoader is not something which isn't defined normally though. Have you included glad.h?

What is the correct method of launching some process from C on *nix?

fork() followed by exec*()?

well I know a bit of C and I liked C# when I was reading the first chapters of microsoft's step-by-step book.
I really don't know which one I should use.

>No you don't.
How so?

I really don't know which one I should learn*

Learning C++ is simply not the same as learning C.
Especially when you consider the programming practices within the two very different languages.
It's true that if you learn C++ you know most of the syntax of C. But that can be said for tons of languages. Any C-like really.
If you liked C# you can go with that.

Well, "undefined reference" is a linker error.

Yep, it's included.
Not including has it instead say it wasn't declared in this scope.

Yeah you're right. Sorry I shouldn't be giving help when tired.
How are you linking?

#include

That's not linking. That's including a header file.
Linking is when you tell the compiler "here's some library files".

isn't the garbage collector a bad thing?
I mean, with C I can free any mallocated memory I want

I don't want to risk a Clinton presidency.

The problem with garbage collection is that you don't control when and where you allocate or deallocate memory. So yes it's correct that it's bad.

But for any game I see you making it shouldn't really be an issue.

But certainly if you're making a professional AAA game you wouldn't use c# simply for that reason. I'm not sure if you can get manual memory management going in C# in any nice way but that's also an alternative.

If your goal is to be low level I'm afraid you're pretty out of luck because OS's prevent that right now.

handmadehero.org is probably something you'd enjoy though. He technically uses C++ but he uses a subset that's very similar to C.

What's the difference?

Haven't done much on my Chip-8 compiler for a while. Talked to my programming instructor recently, and he gave me advice that's actually reasonable and helpful. Just finished a very basic implementation of checking the symbol table (only checking so far, verifying code validity).

Errors still print as if on line 0 because I forgot to keep track of each tree node's line in code. Should be an easy fix.

I'm just gonna link you to something. It's a bit to explain.
stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work

Also I'm not a fan of the stuff the person answering insets. Like the fear of macro's/defines and #includes.

Also Garbage collection is far more efficient now than it used to be. Its performance hit will be negligible in most cases.

That still makes it sound like a linking error is a failure to #include.

It's not really about how much it will hit, it's WHEN that is the question everybody is asking.

I don't have a problem with GC as long as it's not forced on you and the language acknowledges more than half-heartedly that RAII is useful.

GC is a problem for real-time systems

RAII shares some faults with GC

And GC should only be used when your lifetimes really aren't at all straightforward. It's great for copy-on-write semantics, for example, when you don't want reference counting hell.

Like?

Like when your RAII accidentally frees a massive structure

Accidentally?

"accidentally" as in GC "accidentally", i.e. "when i didn't want it to happen"

Maybe in shit languages like C++ where move semantics were an afterthought.

Oh boy

Not for games which care about the stall, they need to be more predictable than GC tends to allow. I'd agree that for non-games without very high requirements garbage collection is quite nice.

But GC is just a more inefficient process overall so it will never beat programmer-managed memory for high-end applications.
Well it isn't. A #include is just a copy paste into a file. The linker takes object files and link them together to a program after compilation.
Both RAII and GC are bad because they're (at least sometimes) unnecessary operations.
RAII is pretty useless because it hides errors you have to deal with.

>RAII is pretty useless because it hides errors you have to deal with.
???

All the other stuff I have without linkers though works perfectly fine.

user it's a thing you have to accept exists and will exist.

It seems odd though, that one library needs linking and another doesn't.

Also I have absolutely no idea how one writes a linker.

I honestly think I could be equally disappointed by either candidate.

The great thing about RAII is that it never does anything on accident. It always frees resources in a predictable manner.

>>Also I have absolutely no idea how one writes a linker.
You don't. You tell your compiler using flags where .lib (for example) files are. I don't know what environment you're in so I can't really help you.
If you're writing your code in a way that relies on RAII you're going to have errors that were reliant on it. As RAII should be removed almost in its entirety if you care about performance you've just introduced hidden bugs until late in development. It's not that easy to see how that happens because it's such a small thing that causes issues on a large scale, and when you're doing it you don't necessarily make the connection. But pay attention next time.
RAII is also annoying to do. Could be easier in some languages,
This is also worth looking at.
youtu.be/TH9VCN6UkyQ?t=1784

>The great thing about RAII is that it never does anything on accident. It always frees resources in a predictable manner.

There weren't any library files though.
I used glad.dav1d.de/ to get the two header files I need.

Maybe you're not compiling glad.c?
See if there's a glad.obj somewhere

There's a glad.c file, but putting it in my lib folder isn't helping.

Could I get to know what compiler you're using or is that secret?
Have you added an include directory (or added a directory to the path environment variable) that points to the folder where include and src (for glad) is located?

CodeBlocks.
I'm new to the IDE, so I don't know how to fix up a naming mistake I made for the include directory a project uses (the root folder is called GLFW even though other things are inside) but I did try having a src folder (with glad.c) alongside my include folder.

But GCs are non-deterministic. You can ALWAYS tell exactly when RAII will manage resources. It may not have been when you wanted the resources to be freed, but it is entirely your fault that it did so.

New thread.