/dpt/ - programming thread

...

Other urls found in this thread:

mingw-w64.org/doku.php/download
astyle.sourceforge.net/astyle.html
twitter.com/SFWRedditGifs

First for traps
>9 posts early

Daily reminder that if your language isn't functional, it's dysfunctional

First for C++

Fuck off trap poster

What are you working on Sup Forums?

Previous thread -

To anybody who knows about PNG image files:

How do I get data out of the IDAT block of a PNG image? I'm trying to get pixels with spatial data and color. I already have code to parse the IHDR and PLTE blocks.

Also, what are common blocks that appear in a PNG that aren't documented? I've noticed a couple common ones.

R8 my Meme C++ singly-linked list!

#include
#include


enum LL_OP { INSERT, REMOVE, AT };
const char *show(LL_OP op) {
switch (op) {
case INSERT: return "LL::insert";
case REMOVE: return "LL::remove";
case AT: return "LL::at";
}
}

template
class LL {
public:
LL(): first_(nullptr), len_(0) { }
template
void insert(Tref v, int n) {
do_insert(std::forward(v), first_, boundcheck(n, INSERT));
++len_;
}
void remove(int n) {
do_remove(first_, boundcheck(n, REMOVE));
--len_;
}
T& at(int n) { return do_at(first_, boundcheck(n, AT)); }
const T& at(int n) const { return do_at(first_, boundcheck(n, AT)); }
int len() const { return len_; }

private:
struct node {
T v;
struct node *next;
} *first_;
int len_;

int boundcheck(int n, LL_OP op) {
if (n < 0) {
n += len_;
if (n < 0) {
throw std::out_of_range(show(op));
}
}
else if (op == INSERT ? n > len_ : n >= len_) {
throw std::out_of_range(show(op));
}
return n;
}

void do_insert(T&& v, node *& cur, int i) {
if (i == 0) {
cur = new node{std::forward(v), cur};
}
else {
do_insert(std::forward(v), cur->next, i-1);
}
}
void do_remove(node *& cur, int i) {
if (i == 0) {
node *temp = cur;
cur = temp->next;
delete temp;
}
else {
do_remove(cur->next, i-1);
}
}
T& do_at(node *cur, int i) {
if (i == 0) {
return cur->v;
}
else {
return do_at(cur->next, i-1);
}
}
};

Is it memey enough?

mingw-w64.org/doku.php/download running windows 10 x64 bit which one am I supposed to install?

>C++
>using const char*

>using enum & matching each case rather than using an enum class or an array

T& do_at(node *cur, int i) {
return (!i) ? (cur->v) : (do_at(cur->next, i-1));
}


void do_insert(T&& v, node *& cur, int i) {

(!i) ? cur = new node{std::forward(v), cur} : \
do_insert(std::forward(v), cur->next, i-1);
}

>>using const char*
nothing wrong with it sperg

>using enum & matching each case rather than using an enum class or an array
>you should do my way!! if you don't you're wrong!!

std::string has length as a member


const char *show[] = { "LL::insert", "LL::remove", "LL::at" };

show[INSERT]

Yeah not bad. I knew these memes tho. Also insert's bound checking for negative values should be different, my bad.

>throwing exceptions
>bounds checking
>random access for a linked list

>not using
const shar* repr[] = {
[INSERT] = "LL::insert",
[REMOVE] = "LL::remove",
[AT] = "LL::at",
}

>shar

How does [INSERT] = "" work?

Oh you're using C literals. Don't think that's valid C++

>how does it work?
intuitively. Last ones have precedence, unspecified ones are null.
>C++
Yeah, dunno

Tuning Uncrustify to my perfect absolute liking. Have you all done that, Sup Forums?

open GL

which one? the x and y parameters have to be there for some reason

A
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}

B
void keyboard(unsigned char key, int x, int y)
{
if (key == 27) {
exit(0);
}
}

>opengl
>keyboard

are you actually retarded?

if you want to quit the application you press Esc

Rate my opengl code Sup Forums

int result = 0;
void AddTwoNumbers(int x, int y) {
result = x + y;
}

sample usage:

AddTwoNumbers(3, 4);
glVertex3f(result, result, 0.f);

my editor already does that if i press Ctrl + Alt + F

non-creative memeing

26th for yung lean

>non-creative memeing
Memeing by its very nature implies the creation of a meme. The essence of memes is that of ideas, the blood of creativity. To suggest memeing can be uncreative is flawed not just a posteriori but semantically.

t. Philosopher King Pepe

decompress the idat data with the compression algorithm in the IHDR chunk
filter the data according to the filtering method in the IHDR chunk
now the layout/total size of the raw data of scanlines are determined by the IHDR

A lookup table with key => callback contents. Also you can do just:
void keyboard(unsigned char key, int, int)


Don't need to specify names.

But that has nothing to do with OpenGL, OpenGL doesn't have anything to do at all with a keyboard.

First time working in Java and still trying to change C++ habits

I want to do something like this:
public class Block {
private int xCoor, yCoor;

Block(int x, int y){
xCoor = x;
yCoor = y;
}
}

public class MovableBlock extends Block{

BodyPart(int x, int y){
super(x, y);
}

public void move(int x, int y){
super.xCoor = x;
super.yCoor = y;
}
}

But apparently you can't edit private variables from super class, and making them public would miss the point. Is there a way without making MovableBlock an another class with mostly the same content as Block?

Maybe... But does it do it YOUR way?

protected

OK Sup Forums, here's a "challenge". can anyone make a program that can solve shit like ((15-3/2)^2*4+3(3*(2/5^2)^3))/((15*3/2)^44+1.5(3*(2/5^2)^3)/1000)+(1-(((15-3/2)^2*4+3(3*(2/5^2)^3))/((15*3/2)^44+1.5(3*(2/5^2)^3)/1000)))^(2^0) ? Have fun ^_^

Oh man, I was sure I heard Java didn't have protected. Thanks

What language? What compiler?

Any language or compiler

well i can configure some parameters like ident, add brackets, add spaces between types, etc

int main(){
int ret = system("echo '((15-3/2)^2*4+3(3*(2/5^2)^3))/((15*3/2)^44+1.5(3*(2/5^2)^3)/1000)+(1-(((15-3/2)^2*4+3(3*(2/5^2)^3))/((15*3/2)^44+1.5(3*(2/5^2)^3)/1000)))^(2^0)' | bc");
printf("%d\n", ret);
return 0;
}

>32512
Sorry user, that's not the answer

...

Nice program

not the same in all languages

Can you do ?
int *pointer;
int& reference;
int&& rvaluereference;
int *& ref-to-pointer;

There are actually people (me) who think this style makes the most sense.
Besides, can you configure line break insertion in a fine-grained way? (if(x){\n}else{} versus if(x){\n}\nelse{} for example? (by that I mean break-before-else))

i don't give a fuck tho

ok so finally got arch linux running with tor/transparency and iptables. Now people telling me i can run a webserver for my own websites and a irc chat room. I do work with PHP and wordpress also a little familiar with apache.

What does g suggest and why?
apache | nginx

...

well, my editor uses this plugin here:

astyle.sourceforge.net/astyle.html

maybe does dunno

> i

What does Sup Forums think of protobuf?

> i < 101

I mean

x86: jge

Here you go .

Python

expr1 = (((15-3/2)**2)*4+3*(3*(2/(5**2)**3)))

expr2 = (((15*3/2)**44)+1.5*(3*(2/5**2)**3)/1000)

expr3 = (1-((((15-3/2)**2)*4+3*(3*(2/5**2)**3)) / \
(((15*3/2)**44)+1.5*(3*(2/5**2)**3)/1000)))**(2**0)

print ((expr1) / expr2) +expr3


output
1.0

void lte() {
for (int i = 0; i

is ^ XOR?
should it be integer arithmetic?

this is compiler specific and only happens if you compile to assembly

with other languages that isn't the case

carry on

Multiparadigm > functional

No it's exponentiation. Just like on TI caculators and with TeX.

Functional is best

>emulate all non-functional paradigms in reasonable code
>pure behaviour isolated, perfect information for compile time optimisation

yet, we're talking about C++ (I used C, but the same "optimizations" are applied in the loop variants)

(and clang, icc, msvc all do similar, gcc and clang also do similar on other platforms like avr, ppc, and arm/arm64)

Yet still slow as fuck.

Only because nobody chooses to write imperative code in functional languages

Haskell has inlinePerformIO, for instance

Daily reminder that if your language is """"functional"""", it isn't functional

>Designed to be practical and useful, rather than attractive
>Working or operating

Is there anything in C more advanced than pointers?

Like, what else is there to learn after making a linked list? What other concepts are there?

dynamic memory allocation

things like undefined behavior

Averaging multiple integers

Garbage collection.

How do you deal with hangnails, Sup Forums?

I have one on my pinky finger and it starts throbbing when I type.

cut it out with a nail clipper and grab a bandaid pussy

1. The only compression format is Zlib, this isn't an issue
2. My test image isn't filtered. I can already read IHDR easily
3. it is never clear about what a scan line is. Also the layout and size are already in IHDR. IDAT is "image data". This is the block were the data (color/order) of pixels should be.

I can't get it to decompress with Zlib.

Thanks for copy and pasting the documentation, user. Very helpful

No excuses.

>>nobody wants to
>excuse
Nice try moron
There are fucking inline C libraries for haskell

If you have to resort to other languages for performance, aside from ASM, your language is no better that a scripting language.

You don't, I already told you.

Then why is Hasklel so slow?

Also >aside from asm
Because your favourite little language has inline asm?
You could write an inline asm extension for Haskell

Because nobody writes imperative & performant Haskell, that's not the main aim of the language. The main aim is to be a good programming language.

How do I get the length of a file in C?

A slow language is shit by default.

The language isn't slow you fucking moron
I've told you this three or four times
People write slow code in Haskell
If you wrote the equivalent to C code it would be faster, and a damn sight uglier

Faster than normal, that is. Not necessarily faster than C.

L E A N
E
A
N

Variadic funtions

>If you wrote the equivalent to C code
impossible, hasklel is not as powerful
>it would be faster
than python?

>impossible, hasklel is not as powerful
You're full of shit.
>than python
You're full of shit.

Learn to fucking program, dumbass.
>lol i write 1+1 in C and its faster than haskell!

>1+1 is slower in hasklel
top fucking kek!

>using the same field name for different records is an unsolved problem
>concurrency is a GHC extension
>everything people like about "Haskell" is actually a GHC extension
>you need the FFI for basic programming concepts
>"good programming language"

GHC extensions are part of what most mean by Haskell

It'd be like saying "show some concise C++ code to do x"
"oh you used std? standard library doesn't count"

Yeah, because Haskell has a runtime.

not possible; c doesn't concern itself with such pleb issues

>Yeah
shit language confirmed

>performance is the only thing that matters
Non-programmer confirmed

Except GHC adds so much more to Haskell that it's practically a different language.

>"show some concise C code to do x"
>uses C++

>performance is not that important
webshit confirmed

What most people mean by Haskell is GHC + extensions, not Haskell 98

Didn't say it's not performant, did I faggot?
Said most people write slow code.
Apparently I need to say this to you YET ANOTHER FUCKING TIME.

Maybe stop putting words in other peoples mouths and start taking the dick out of your own?

how do i put a C++ text-based space tactics game i made as a personal project into my resume, or should i even? i've only been working on it a week and it's already getting pretty in-depth. but it's looking a little ugly as fuck since i listened to /dpt/s advice and made all the variables and functions public since private's a csci degree meme

i was going to give advice, but then i saw the word "meme"

get fucked kid

memesters leave