/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

en.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_(LRU)
leetcode.com/problems/lru-cache/discuss/
en.cppreference.com/w/c/io/fread
en.cppreference.com/w/c/io/fgets
twitter.com/SFWRedditImages

Based china spammer, bringing back old Sup Forums. Now we just need some gore and scat for the full experience.

>before bump limit
no

Guys i love this program called Rockbox but I barely know shit about how software development, only took 2 semesters of java. How do i get started on this so I can get this working for other devices, specifically my Cowon plenue d?

>"Project 1: write an LRU CPU cache simulator in c++ and calculate statistics"
>don't know c++
>don't know how caches work
>don't know statistics
>entire project is due in less than a week

yabba dabba doo, my existence is poo

chicken scheme uses a sort of amortized trampoline. uses the C stack to allocate stuff in the gc nursery, and just uses C function calls directly. When the nursery/stack fills up, it copies live data from the nursery/stack to the heap, and blows away the rest of the stack with longjmp.

Gives you fast tail call support and allocation.

and instead of learning these you are shitposting here.

start here
en.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_(LRU)

then here
leetcode.com/problems/lru-cache/discuss/

whats this public static thing called?

Method header.

nevmnd, found something on google

inefficiency

>chicken
>"sane"
it's amongst the slowest scheme implementations.

Anyone know some place where I can go and make programs people request for free?
I want to get experience making stuff people actually ask for. I feel no passion for projects that I do for the hell of it.

it's still pretty neat and it works well

after some test, even chicken is turning tail call into goto.

entry point?

A static """method""".

So in C and C++ the rule of const keyword are pretty consistent. It always make something left of it as const:
T //datatype T, modifiable
T const //datatype T, can't be modified by any means
T const & //reference to a constant T
T const * //pointer to a constant T
T * const //a pointer that always point to a T, and can't be changed to point to other object. The T is not constant
T const * const //a constant pointer to a constant T
//In a method:
void Foo::Bar() const //a method that callable by constant Foo, and can't change any value in the *this object

But why lots of people still write it as const T foo; ???

Learn Agda first.

Avoid Agda at all costs.

is there any way to make the java compiler allow emoji class names?
I know the jvm definitely allows it

If Agda is too difficult for you, then consider finding another hobby.

What is the best function in C that allows me to read from a file (i.e. copy the char from a file into a array of chars) until a certain character?

What's a good IDE for OpenGL programming on windows?

bump this question

emacs

*dabs*

stop

en.cppreference.com/w/c/io/fread

>you should learn javascript first
>if you think otherwise, it means javascript is too difficult for you

>you should learn javascript first

lru is piss easy
write a prototype in python or javascript or any other language you know then translate it to sepples

he was quoting someone idiot

Quite surprised to find that Gvim renders Emojis in color.
Sadly, this does not compile.

Who was he quoting?

no clue

Whomst are you quoting?

Whom

But that funtion will read until n-1 charachters, which is not what i want. I want it to read until a certain charachter appear. In this instance it is \n

What is the equivalent to this function int feof(FILE *stream) but to test end of line?

Are you from the early 20th century?

>forcing OOP so hard that standalone functions must be implemented as public static methods under some arbitrary class

In another thread, someone mentioned they made a script to check if a word was a palindrome

Trying to get out of braindead end user support gig and back in programming but I cant even picture the pseudo code for this in my head.

Halp

Correct use of static methods in my opinion returns the class it is encapsulated in with some special stuff that the constructor can't do.

1. reverse the string
2. check if the result is the same as the original string
not the most efficient approach but it's hopefully easy to understand

>whomstvnt're art thou quoting
/dpt/sms.

so this is the power of oop

Alright my negroes, I'm shitting myself with simple stuff like chars and pointers.
Consider the following prototype:

void TestFunc(char input[])

And the function being called:
int main()
{
TestFunc("Fuck me in the ass!");
}

This will give an error because const char * can't be implicitly converted to char *. Alright, but then why the fuck does this work: char input[] = "Fuck me in the ass!"

Step through the strong from front to mid and back to mid simultaneously and check for characters?

Have 2 index variables, one that starts at the beginning and goes forward, and one that starts at the end and goes backward. Keep checking until the indexes cross (you have a palindrome) or until the characters don't match (you don't have a palindrome).

why am i retarded?

I was picturing a loop comparing the first and last, then increasing the first index and decreasing the last index

>believing java has anything to do with OOP

that probably depends on the C compiler and how much optimization it does. chicken just generates C code.

that would work too and probably be faster, but trickier to implement correctly

the second one, the compiler knows how long the string is. the first one not so much. you can kind of just imagine the compiler slipping a sneaky `19` in to make it `char input[19] = ...`. it can't (or doesn't) do that for a function's argument.

Employed Haskell programmer here

ssize_t getline(char **lineptr, size_t *n, FILE *stream);
ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);

fgetc
loop it

correction: would be [20] rather than [19]. i'm still drunk from last night though so yeah. deal with it. good luck learning computer.

What's the best set up for using GCC on Windows?

Employed Idris programmer here

>tfw there's a greater number of employed Brainfuck programmers than Haskell ones

unless chicken itself is optimizing away some function calls, which is also possible

To be fair that's probably true for most language.

i don't think i know of anybody who *only* knows haskell. everyone i know who makes any money with niche platforms (yes, haskell is a niche platform) is familiar with all the basic boring stuff too, and uses them in some capacity.
javascript on the other hand - there are plenty of people who genuinely know no other language and would be utterly lost if you sat them down in front of something that didn't look vaguely like C.

Ok, got it senpai.
After a little googling I learned that I can cast it like this: TestFunc((char*)"Fuck me in the ass!");

Is this really the best way to handle this? This function will be called a lot and I don't wanna having to put a casting every fucking time. I can also handle things on the function side, but I can't figure it out how to do that without having to use a buffer variable.

>This will give an error
it werks for me

fgets then

>After a little googling I learned that I can cast it like this:
Not him, but just don't do that. The reason the compiler screams on you is that string literals are embedded in the binary's data segment, and if you try to modify them, you will probably die from a segfault. If your function doesn't need to modify its input, just do this:
void testFunc(char const *input) {
}

int main() {
char bar[] = {'b', 'a', 'r', 0};
testFunc("foo"); // okay
testFunc(bar); // also okay
}

en.cppreference.com/w/c/io/fgets

The first one fails because input is not an array, it's a pointer.

Second one works because input is actually an array.

I'm on the loops chapter now.

import java.util.Scanner;

public class Main
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
boolean okay;
do {
System.out.print("Enter a number: ");
if (in.hasNextDouble()) {
okay = true;
} else {
okay = false;
String word = in.next();
System.err.println(word + " is not a number");
}
} while (!okay); //What is this?
double x = in.nextDouble();
}
}


I'm confused as to what's happening with the while condition. Like "okay" is a boolean with no assignment right? Then it gets assigned inside the do statement right? So how does "!okay" work as a condition?

>Haskell
Someone told me to learn Haskell first since I have a(n unused for years) maths background but I already bought the books for java.

here
is spot on. way more concise than what i was typing, too.

I know this is true for C++, but is this true for C too?

>I already bought the books for java
oh shit user, what are you doing

Why? It wasn't expensive, it was the humble bundle set from a few months back.

you's got mo money than brains niqua

That's what I was going to do, but I wasn't sure. Also, I'm going to have to create a new variable inside my function because I actually need a char * (to pass as an argument to a system function) and not a const char *. But if that's the proper way to do it I don't mind it.

i have no error with clang nor gcc

>is this true for C too?
Yes. I guess it's worth noting that you can create a normal array using the string literal syntax like this: char arr[] = "str"; You're allowed to modify that, and sizeof(arr) will actually actually give you the length of the string (terminator included).

>Parsing stops if end-of-file occurs or a newline character is found,
Didn't read the part "newline"

thank you, my niggas

It was 10 quid. Can you help with my problem anyway?

>(to pass as an argument to a system function)
What system function takes a non-const char *?

What is "quid"?

It stays in the do while as long as okay is false. When it's true because there's a double in the input in, it leave the loop.

the boolean variable isn't being assigned, it's being evaluated (and negated)
the while statement takes the result of the evaluation, and if it's equal to true, it keeps looping, otherwise it steps out of the loop

>It stays in the do while as long as okay is false. When it's true because there's a double in the input in, it leave the loop.

I understand that but how does "!okay" = not true if the boolean isn't assigned true from the beginning?

A Windows one

whats wrong with james?

How to determine if a number is divisible by 4 in x86 assembly? Like 01100100 which is 100, is divisible by 4 and I wanna jmp if that is true. Having trouble breaking this down.

Ok, I understand now.

>tfw a brainlet tries to program in haskell

He just realized that OOP objectifies women and girls.

That's fine as well.

He browses Sup Forums

I want to be able to detect commercials on tv and black them out. What can I use to do this? OpenCV? ffmpeg?

Just what the fuck are some values in COCOMO II based on?

0.22 for defects?
Time per men? Who came up with this bogus?

You have a type conversion error because a const can’t be demoted to a non const. You can however promote to const.

So, according to your compiler, a string literal is const.

And if it were to work (like people are saying) then the string would be undefined if you were to change the string in any way. Your solution might be to make your function parameter const char[]

Pick an open source project of your choosing and look at it's bugtracker/feature requests?

test reg, 0b11
jz divisible_by_four