[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 337
Thread images: 37

File: 1502554078961.png (111KB, 600x800px) Image search: [Google]
1502554078961.png
111KB, 600x800px
What are you working on, /g/?

Previous thread: >>61868339
>>
>>61875133
Anyone built something with Haskell, if so what was it?
>>
>>61875159
I think Idris was made in Haskell
>>
>>61875159
Nothing practical has ever been nade in Haskell. Only academic circlejerk projects.
>>
File: 1474325315193.jpg (44KB, 636x616px) Image search: [Google]
1474325315193.jpg
44KB, 636x616px
Employed Haskell programmer reporting in
>>
>>61875195
So, how are you finding the latest JS framework?
>>
>>61875133
stop using that image
you're scaring the children
>>
File: dlang_chan.jpg (139KB, 470x545px) Image search: [Google]
dlang_chan.jpg
139KB, 470x545px
Germany loves dlang-chan!
https://dlang.org/blog/2017/07/28/project-highlight-funkwerk/
>>
splitvalue = *(&(&tp->v0 + tv)->x + axis);

Is this acceptable to you?
>>
>>61875133
Variety is the spice of life, OP. You, on the other hand, are Miracle Whip spread on Wonder Bread.
>>
>>61875287
no
>>
>>61875195
What do you do?
>>
Trying to wrap my head around how C handles headers.

Pic related is my setup for an implementation of linked lists. However, when I try printing the value of "p->Next", I get the following error (gcc)
Test_Poly.c:12:41: error: incomplete definition of type 'struct Node'
printf("Address of p->next: %d\n", p->Next);
~^
./Polynomial_List.h:3:8: note: forward declaration of 'struct Node'
struct Node;


Why is this happening? Don't I include the header file, which specifies how Node should be built?
Using the following gcc command to compile:
gcc Polynomial_List.c Test_Poly.c
>>
>>61875520
either say
export struct node;
in the header
or just define it in header fully

i think that would work
>>
>>61875520
Can you please show the filenames of all the files you included

The top right header file just declares the existance of the struct Node, but doesn't declare what fields it has. The bottom right header file declares what fields it has.
In order to use fields such as ->Next, you need to include the bottom right file, and in order to use those functions you need to include the top right file.
>>
>>61875619
nigga the file on the left includes the header
and he compiles both of the .cpp files
use your eyes
>>
>>61875656
Okay so the bottom right file is a .c file but that's wrong, it needs to be a header file that the left file includes.

The key takeaway here is that compiling multiple C files at once is the same as compiling them seperately. So if you were to just say
gcc Test_Poly.c -c

then it has no way of knowing what ->Next is. So you need to tell it that information by declaring it in a header
>>
>>61875619
Yeah sorry.

Left file is "Test_Poly.c"
Top right is the header file Polynomial_List.h
Bottom right is the implementation file Polynomial_List.c

>>61875675
I'm thinking of ways I can include both the implementation and header files, but I'm worried that might lead to duplicate symbols and leading to compiler errors

Not sure if this helps, but when I
#include "Polynomial_List.c"

int the left file, I get linker errors (duplicate symbols errors for the functions defined)
>>
>>61875675
>it needs to be a header file that the left file includes.
but that's wrong
>>61875728
you're getting duplicate symbol errors because the poly-lists header should have a
#define Polynomial_List_H

right after the #ifndef
right now that #ifndef never does anything
>>
>>61875728
pretty sure you want to do something like this:

https://en.wikipedia.org/wiki/Opaque_pointer

either define functions to return the inner values required or expose the struct definition in the header file
>>
>>61875728
Don't include the header. There's no reason to have a header file anon. This isn't sepples. You only need header files when you are thinking about an interface and then you'll link against the .o file not the .c file.
>>
>>61875728
Functions get compiled into assembly code, and if the same function gets compiled twice (which is what happens when you #include the .c file) then you get a linker error.

However, struct declarations are not compiled into anything. As long as each c file sees the same definition of a struct, you're good to go.
examples:

// a.c
void foo() {}

// b.c
void foo() { printf("yikes"); }

result: LINKER ERROR

// a.c
struct thing {
int x;
};

void foo(struct thing) { printf("x = %d\n", thing.x); }

// b.c
struct thing {
int x;
};

void foo(struct thing); // note: this is a DECLARATION not an IMPLEMENTATION

void bar() {
struct thing;
thing.x = 4;
foo(thing);
}

result: x = 4 (GOOD)

// a.c
struct thing {
int x;
};

// b.c
struct thing {
double y;
};

result: this compiles, but is undefined behavior since a.c and b.c see different versions of struct thing. never do this.
>>
>>61875756
Alright... I should have seen that coming, but unfortunately I don't think that did anything (see pic related)

>>61875778
I want to include header files because it makes it easier to organize imo.

>>61875799
>As long as each c file sees the same definition of a struct, you're good to go
But don't I do this? I have a declaration of a struct, and define it in an implementation file.
>>
>>61875843
Each C file needs to see the definition of a struct. The only way it can "see" it is by having it be inserted into the file.

// a.c
struct thing { int x; }

// b.c
// note: does not #include anything
void foo() {
struct thing t.
printf("%d\n", t.x);
}


$ gcc a.c b.c
ERROR: b.c doesn't "see" the definition of the struct, so it doesn't know that the field .x exists
>>
>>61875159
xmonad was built in haskell
>>61875185
it was heavily used in the corporate world as a fast, safe language before java and C++ came into the picture.
>>
>>61875843
>But don't I do this?
i think the test-poly still sees the undefined struct, might be wrong

you should really be defining structs in the header, not in the .c file
>>
>>61875869
>
>>
>>61875843
Not the same anon but you just need to put the struct definition in the header, basically instead of this:

struct Node;


Put this:

struct Node
{
int Coefficient;
int Exponent;
struct Node* Next;
};


And then get rid of the definition in the .c
>>
>>61875520
The header defines a function the name of which should point somewhere. That somewhere would be a library file linked to your program.

Basically the header file does nothing but to announce the existence of the function, alone it's worthless. The library/binary file the function is in (if it's not called from the file itself) defines what the function is.

So for example
#include <stdio.h>
will bring in symbols from stdio, therefore tell (promise to) your program that the function printf (and every other in stdio) exists. Doing -lc when compiling (often done by default by your compiler) will have the program call the libc library in which it will find the actual printf function.
>>
Netbeans-Cpp IDE is pretty comfy.
>>
>>61875869
>xmonad
>Pure and innocent window manager written in 1.2 kLOC.
>Built on top of the heaping garbage fire known as X11.
It hurts.
>>
>>61875866
I moved the definition of Node to the header file... Never thought I'd be so happy to get a seg fault!

Many thanks to everyone!
>>
>>61875953
any day lad
>>
>>61875953
what in the world are you editing text with? This looks like software from the 90's that was ported to cocoa, and it looks even worse than acme.
>>
>>61875984
Emacs... So exactly what what you described.

On an unrelated note, anyone know why the value of p-> Next changes between a function call?

void Initialize(Polynomial p)
{
p = (struct Node*) malloc( sizeof(struct Node));
p->Next = NULL;
printf("Printing P->NEXT: %d \n", p->Next);

}


int main()
{
Polynomial p;

Initialize(p);
printf("Address of p: %d\n", p);
printf("Address of p->Next: %d\n", p->Next);
}


And output is below:
Printing P->NEXT: 0  /* In function Initialize(p) */

/* In main */
Address of p: 136380470
Address of p->Next: -1991765899
>>
>>61875984
looks like some type of vim application
>>
>>61876012
functions only change the inputted values locally
if you want to change p's value use a pointer
pass the function &p and use it in the function as p*
>>
Rate my 7th C++ program
#include <iostream>
#include <string>
using namespace std;

enum class monster_t {
ogre,
orc,
dragon,
giant_spider,
slime
};

struct monster_detail {
string name;
int health;
};

struct monster {
monster_t type;
monster_detail detail;
};

string get_type_string(monster_t m)
{
switch (m) {
case monster_t::dragon: return "dragon";
case monster_t::giant_spider: return "Giant spider";
case monster_t::ogre: return "ogre";
case monster_t::orc: return "orc";
case monster_t::slime: return "slime";
}
}

void print_monster(monster m)
{
cout << "This "
<< get_type_string(m.type)
<< " is named "
<< m.detail.name
<< " and has health value: "
<< m.detail.health << endl;
}

int main()
{
monster T{
monster_t::ogre,
{"Torg", 120}};
print_monster(T);
return 0;
}
>>
>>61875929
nice to hear
>>
>>61876049
are you going through a game development book?
>>
>>61875316
You have no taste anon. Code like that is the only reason I still bother with this crap.
>>
>>61876076
Nope, it's http://www.learncpp.com/
Pretty nice resource if you ask me
>>
>>61876043
Oh duh...

I guess I just forgot about this because I was working with pointers and assumed I could change values will-nilly

>>61876049
My only concern is that it's not very prone to being expandable (what if you had 100 monster types? A gargantuan switch/case statement isn't exactly something you would want to type out)

I recommend having an array of structs and a file for monster names... But not really into game development (yet) so take my concern with a grain of salt
>>
>>61876049
2/10
all pretty silly
it would be smarter to have a map that maps strings of monster names -> structs of monster stats
>>
>>61875952
>not creating a pure Linux opengl es context by using generic buffer manager and kernel mode setting
>not creating your own hardware accelerated graphics
>not grabbing input directly from evdev
>>
>>61876087
i'm not a game dev but to me it seems like it'd be better organized if you make a class for every monster than inherits from the monster class. also, if you're not trying to do OOP stuff don't try to learn cpp
>>
>>61876139
This kind of shit is why I'm not productive in Linux. I end up fucking with the env endlessly instead of working.
>>
We need a pastebin.
>>
found an old fizzbuzz i wrote a few years ago. what was i thinking

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define Oo 100ULL
#define __(oo,oO)\
for (o=(Oo*(oo)>>(oO));o<=Oo;o+=(Oo*(oo)>>(oO)))OO ++[O]

int _o(const void *o, const void *O) { return
((*(uint64_t*)o) >> 48) > (uint64_t)(*((char*)O + 6)) ;}

int main(void)
{
uint64_t oo, oO, o, O [Oo * 0x1bbbbbbbd4 >> 36], OO = 0;

__(0x3e0f83e1ull, 35) = (o << 060) | 2054842694;
__(0xcccccccdull, 36) = 0x7a7a7542 | (o << 48);
__(0xa57eb503ull, 38) = (uint64_t)0xff << 36 | (o << 0x30)
| ((o + 0x30 - 10 * (o * 205 >> 11)) << 010)
| (((0x1999999a * o >> 32) + 0x30)); qsort(

O, OO, sizeof(0[O]), _o);
for (o =0;o <OO;o ++) {
oO= o[O] >> 060; oo =o;
while (!(oO^ (o [O]>>48)) && (o [O]&16711680))
printf("%s", (char*)&o ++[O]);
printf(!(o ^oo) ? "%s\n" : "\n", (char*)&o [O]);
} return

0;
}
>>
>>61876177
What should be on it?
>>
>>61876172
But that's the purpose of Linux, of programming. Making programs for other people is for idiots. Do it for yourself
>>
File: terrain.png (2MB, 1920x1080px) Image search: [Google]
terrain.png
2MB, 1920x1080px
>>61874357
>>61874664
>>61874691

>>61876065
>>
>>61876049
If you're dispatching on type (in your case the big switch statement) you should consider a polymorphic approach instead.
>>
>>61876224
Nigga I'm lazy. I have work to do unrelated to my environment, and I generally would like to get that work done. The problem with Linux is sharpening that particular axe is alluringly straightforward, so if I don't check myself I end up grinding metal for hours instead of just chopping the fucking tree down. As weird as it sounds, knowing nothing about how the dev tools I'm using work under the hood leads to far greater productivity for me.

>Making programs for other people is for idiots.
That's pretentious as fuck. I write code for people who can't, but will pay me for my efforts. In turn I pay contractors, attourneys, doctors, etc. for services I need but don't have the time to become an expert on. Eventually you'll need to pay for someone to do something you can't. That doesn't make then superior to you, and you knowing how a computer works doesn't make you superior to others.
>>
>>61875953
If you don't want to define Node in the header, you could also have used a function (inside the header) that took a struct Node pointer and returned the next of it. That's why the error existed. The struct definition was hidden inside the implementation, so the compiler doesn't know how to dereference it in main.
>>
>>61876142
>inheritance
lol
>>
File: terrain.png (479KB, 800x600px) Image search: [Google]
terrain.png
479KB, 800x600px
>>61876258
Innovation! This new version allows the dividing planes to not be positioned perfectly at the center of the sphere. This means that elevation changes won't be forced into symmetry at antipodes.
>>
File: trap-programming.png (1MB, 1127x1600px) Image search: [Google]
trap-programming.png
1MB, 1127x1600px
>>61875953
Next time you're having problems, try wearing some thigh-highs and girl clothes. They always help me solves any issues in my programs.
>>
>>61876217
RTFM and Google for Retards
>>
Memes
>>
File: terrain.png (999KB, 1920x1080px) Image search: [Google]
terrain.png
999KB, 1920x1080px
>>61876380
1920x1080, fewer slices

Elevations:
Magenta: Z < -2
Blue: -2 < Z < -1
Cyan: -1 < Z < 0
Green: 0 < Z < 1
Yellow: 1 < Z < 2
Red: 2 < Z
>>
File: elevation.png (971KB, 1920x1080px) Image search: [Google]
elevation.png
971KB, 1920x1080px
>>61876489
Where Z = (pixel's elevation minus mean elevation of all pixels) / standard deviation of all pixels' elevations, of course.
>>
>>61876049
>>61876352
>>61876142
These are correct responses

>>61876088
This is not

>>61876375
this guy is just being edgy

There are good arguments to me made against OOP but "lol inheritance" is not one of them.
>>
>>61876012
EVERYTHING in C is PASS-BY-VALUE. Which is why you pass pointers to stuff to save your results outside a function. You pass-by-value a pointer so that when you dereference it the memory pointed at is the same.

Polynomial Initialize()
{
Polynomial p = (struct Node*) malloc( sizeof(struct Node));
p->Next = NULL;
printf("Printing P->NEXT: %d \n", p->Next);
return p;
}


void Initialize(Polynomial *x)
{
Polynomial p = (struct Node*) malloc( sizeof(struct Node));
p->Next = NULL;
printf("Printing P->NEXT: %d \n", p->Next);
*x = p;
}
>>
>>61876508
Isn't multiple inheritance the feature that's looked upon with disdain? And if I recall correctly, C++ is the only major OOP player that supports it.
>>
>>61876548
Inheritance in general is viewed in a far more negative light than it used to be.

Extending functionality in a way that doesn't require dynamic dispatch is done with mixins or composition.

Dynamic dispatch is the only reason to model with inheritance, and it's not a very good one with today's languages.
>>
>>61876541
Thanks!! I kind of completely forgot about pass by value (because I'm kind of used to pass-by-reference in sepples)

Everything works now! I even made an addition function!
>>
is there like a cheatsheet for common/useful methods/imports (in java)?

ive done c++/c# for a few years now as its the standard at my school and while learning java im having trouble thinking of the useful methods i could use instead of doing everything manually.

stuff like string.replace() is super basic but i was doing that shit manually with loops for too long before realizing it was a thing.
>>
File: terrain indexed.png (3MB, 3840x2160px) Image search: [Google]
terrain indexed.png
3MB, 3840x2160px
>>61876504
Simple worldbuilding...
>Magenta/blue/cyan: Ocean
>Green: Continental shelf
>Yellow: Habitable land
>Red: Uninhabitable mountains/plateaus

In this 4k image, we have one big continent, composed of a big landmass, a small landmass, and a bunch of smaller islands. The continent technically extends underneath the northern ice cap, and there are a few undiscovered islands (yellow dots in the upper-left area of this picture), since the people living on the bigger landmasses haven't yet invented ocean travel.
>>
>>61876548
A lot of people criticize multiple inheritance, whether or not that's fair is up for debate. Python also supports multiple inheritance. Java classes may implement multiple interfaces which is sorta like multiple inheritance.

But what we're talking about here is _not_ multiple inheritance. Multiple inheritance is when one class can have multiple parent classes. In this situation we're talking about one parent having many subclasses, which is considered perfectly fine among people who are into OOP.

There's a growing but still certainly minority opinion that inheritance in general is "bad". This is a position that's come out of seeing people abuse inheritance and a few vocal high-profile language designers advocate "composition over inheritance" which is not a blanket dismissal of inheritance but a statement that inheritance is not the solution to every situation where you want to reuse code.
>>
>>61876667
Usually when I'm using a language I'm not sure familiar with, I scoure the documentation for something I want and if I don't find it very quickly I'll write it myself.
>>
>>61876698
The java documentation is absolutely fucking garbage because you have to go to the parents of the parent of the grandparents to see wherever the fuck a method exists and its signature. Just google shit and you more likely than not find a solution with an example on stack overflow from people tired of the same garbage.
>>
>>61876739
This is one reason why I love Racket, it has absolutely excellent documentation that makes it very easy to find out how something is supposed to be used and find related functions for the same kind of data.
>>
>>61876548
multiple inheritance is if you had "Slime" inherit from "Monter" and also from "DungeonCritter". what i described isn't multiple inheritance
>>
>>61875133
If I had to devote my energy to learning a language that will get me employed between clojure and Haskell, what do you recommend?
>>
redpill me on rust /g/
>>
>>61876771
Clojure will get you employed. As a Haskell lover who doesn't really have any interest in Clojure I still acknowledge that it has more applications in webdev jobs and the such
>>
>>61876771
if you only know clojure and haskell it seems you're oriented towards app development, so java
>>
>>61876682
>>61876762
Yes, I know. Jesus christ. The implication of my question was to clarify whether or not the anon who laughed at inheritance was referring to single or multiple variety. Please read more carefully before replying.
>>
>>61876776
Rust is a meme. Improve yourself at C. Unless you want to waste time fighting the borrow and the lifetime checker and putting "unsafe" before writing C.
>>
>>61876818
I've been using rust for a few days now and I only ever fought the borrow checker once; it seems more than obvious how it works, does it not?
>>
>>61876846
Not for C weenies
>>
>>61876818
>>61876846
I should also mention that it's very difficult to write C that does lots of buffer manipulation, whereas writing Rust that does so is trivial. So much so that it's easier to write Rust that does the heavy lifting and export unsafe C bindings.
>>
>>61876846
It is. That's how you write C that doesn't segfault. No training wheels required.
>>
>>61876818
Rust is fine for its purposes. I still use C heavily but that is mainly when doing embedded and other no-allocation based stuff.

I've written >10K+ lines of rust and haven't needed to use unsafe once at all. The borrow checker and all that isn't too big a deal I don't think, and I'd just advise people to make unnecessary clones when they start of to ease in to it.

The big boon to productivity for me is that it prioritizes performance in a way which I won't be stuck at some point in the future at some wall where I may otherwise be with something like python. That and the fact that libraries and the like are so much easier to use which makes it much easier for less low-level things like api-servers and the like.

There are some things I don't really like using it for but in general, it makes you feel confident in the small details and lets you focus on the actual program logic.
>>
>>61876897
If Rust was just C with a borrow checker, I wouldn't use it.
If Rust was C++ with a borrow checker, I still wouldn't use it.
>>
>>61875133
C# is such an incredible language with an incredible IDE Loving it so far.
>>
>>61876910
I've found it most comfortable to use a hybrid approach: Rust staticlib for high level code, compiled together with C to start and do certain syscalls
>>
>>61876739
>The java documentation is absolutely fucking garbage because you have to go to the parents of the parent of the grandparents to see wherever the fuck a method exists and its signature
Inherited methods are listed on every doc page, is clicking one link really that hard for you?
>>
>>61876799
How the fuck does

> Isn't multiple inheritance the feature that's looked upon with disdain? And if I recall correctly, C++ is the only major OOP player that supports it.

imply

> clarify whether or not the anon who laughed at inheritance was referring to single or multiple variety

you illiterate shit?
>>
>>61876972
he probably just learned what multiple inheritance is recently and wanted to use it in conversation. be easy on him
>>
>>61876972
Because it's written according to the rules of the English language, and if you knew English you'd be able to correctly comprehend its meaning. As such, calling me an "illiterate shit" shows me the dire severity of your ignorance. Are you an ESL pleb?
>>
>>61877077
Wrong, here's a list of the things >>61876548 implies:
- You're unsure of how multiple inheritance is viewed
- As far as you know C++ is "only major OOP player that supports it" (which is wrong)
- You're asking for clarification on how multiple inheritance is viewed

Nothing in that post implies it was a question directed at >>61876375 , nor is there any mention of single inheritance.

Points though, for calling me an ESL pleb when you can't figure out what your own post means
>>
how do I make my own proglang
>>
>>61877278
assuming proglang is short for programming language
write a parser + compiler/interpreter

that's it
implementing a basic scheme implementation for example is easy as fuck
all you really need are:
define
lambda
cond
if
else
and
or
quote
inc
dec
cons
cdr
car
null?
number?

and a few other things I'm forgetting
most of the other scheme functions can be defined in terms of the above
+ is just repeated inc
* is just repeated +
let is just a lambda
etc....
>>
>>61877376
how do I write a Lisp sexp parser?
>>
File: t3_6diw4m.png (145KB, 800x533px) Image search: [Google]
t3_6diw4m.png
145KB, 800x533px
>>61875133
working on banging ur mom lol
>>
>>61875133
I've just learned that I can put a static array inside a struct, so I can copy the entire array with only one assignment.
Pretty cool trick!
>>
>>61877413
I'm not going to spoonfeed you
go see how others do it
go look into parsing in general
google it for fucks sake

you'll learn nothing if I tell you everything
>>
>>61875133
It is nice that whoever made this image thinks "backend" and "web development" are two different categories and that "backend" belongs with "scripting".
>>
>>61877468
in what case would this be helpful?
if you're passing to a function you're already copying, that's just how functions work
if you're not passing to a function and you're just working with it, why copy it
what use cases does this help exactly?
>>
Wrote dependency resolution algorithm using preorders. The time complexity is probably terrible but it works well (and in this case n is usually small)
It's fairly elegant

  ;; evaluate a preorder using reflexivity + transitivity
(define (dep<=? p1 p2) (dep>=? p2 p1))
(define (dep>=? p1 p2)
(or (equal? p1 p2)
(ormap (λ (p1-) (dep>=? p1- p2))
(hash-ref preorders p1 null))))

;; sort paths by preorder and return corresponding asts
(map cdr (sort asts dep<=? #:key car))
>>
>>61877490
the entire thing was made ~4 threads back for the sole purpose of pissing people off

the guy that made it used it as the OP image for the last 3 threads
>>
>>61877519
>>61877490

The only reason people have deviated from the old yuki image was pissing people off. I still remember the dpt image wars
>>
>>61877501
arrays aren't copied when passed to functions
>>
>>61877413
Literally the easiest parser there is. Start with an empty list and read each symbol.

Open paren -> create new list, append to parent, this is now the current list
Close paren -> append the current list to the parent list. Parent list is now the current list
any other symbol -> append it to the current list

Fun fact: for reasons of tradition lisp parsers are generally called "readers"
>>
>>61877468
Seems wierd unless you knew what the largest such array could ever be or every such array had the same number of elements.
>>
Should I proceed with CS degree or math degree if I want to work in crypto?
>>
>>61877603
do you know of a lisp reader example written in C?

I've created s-exp readers in dynamic languages before but it's much, much easier there due to the ease of string manipulation
>>
>>61877646
Do both. You'd probably have enough paper overlap that there is not much extra work at all. Are the departments separate where you are studying?
>>
>>61877598
???
then why does this work?
#include <iostream>
using namespace std;

void prtarr (int v[10]) {
for (int i = 0; i < 10; i++) {
cout << v[i];
}
}

int main () {
int b[10];
for (int i = 0; i < 10; i++) {
b[i] = i;
}
prtarr (b);
return 0;
}
>>
>>61877686
That declaration is deceptive and v decays to an int pointer.

https://stackoverflow.com/questions/1461432/what-is-array-decaying

If you want to enforce the size of the input array you can do something like this (in C99), but it still decays to a pointer to something like `sizeof(v)` will be the size of an int pointer so be wary.

void prtarr (int v[static 10]) {
for (int i = 0; i < 10; i++) {
cout << v[i];
}
}


This will give an error if an array which cannot be determined at compile-time to contain 10 elements is passed. More elements is still fine so its not exact.
>>
>>61877723
didn't notice you were using C++. Look at http://en.cppreference.com/w/cpp/container/array
>>
>>61877671
Yes. Math crypto course is 3rd year and CS security is also 3rd year, both with long prerequisites.
>>
>>61877723
ah, I see. the compiler does shit to try to help you, but in your use case it just gets in the way. yeah?
>>
>>61877654
There are plenty of examples, I know the steel Bank CL interpreter is written in C but it's full featured, there's a lot of code there, you'll have to do some digging (which is not a bad thing, great way to learn, just work).

Are there any issues with string manipulation you're having in particular? It's definitely a lot more ceremony to mess around with strings in C but it's not fundamentally different.
>>
Clojure is amazing!
>>
File: 5819995642.jpg (20KB, 332x304px) Image search: [Google]
5819995642.jpg
20KB, 332x304px
Do you fags write actual useful programs or just meme sample code to show off here?
>>
File: 1497484828388.png (316KB, 500x556px) Image search: [Google]
1497484828388.png
316KB, 500x556px
quick, post a fizzbuzz using 5 stars and a cyclic linked lists written in ANSI C
>>
>Fixed-length arrays must have their size determined at compile time.

so why I can do this?

#include <stdlib.h>
#include <stdio.h>

int main(){
int size;
scanf("%d", &size);
int array[size];

for(int i = 0; i < size; i++){
array[i] = i;
}
for(int i = 0; i < size; i++){
printf("%d\n", array[i]);
}

return 0;
}
>>
>>61877778
in a dynamic language, my usual parsing routine would consist of reading a big string from file, splitting it on space, using a regular language to classify the tokens, and then running a parsing algorithm on the token list, either a custom recursive descent parser, a generated one or an Earley with a custom grammar fed to it

It's been so long since I used C I don't even know how to load data from files anymore, so I just hardcoded a simple Lisp program in the source code. I don't know how to split this shit either, I don't have regular language support either... I'm basically fucked
>>
>>61877838
>scanf("%d", &size);
> int array[size];
>>
>>61877838
https://en.wikipedia.org/wiki/Variable-length_array
>>
>>61877849
yes, why can I do it
>>
>>61877808
I mostly keep busy with my CS assignments and programming book exercises
once i git gud at C, scheme, and the SDL library I'll start work towards my first personal project tho
>>
>>61877862
Do you know what the user will type in during compile time?
>>
>>61877778
I can't find a single C file in SBCL's repository
>>
Clojure us amazing!
>>
>>61877808
I generally just write programs to fulfil my needs as I go. The last programs I wrote recently were one to search a list of directories for duplicate files and offer an option to delete either of them in a way that's fully scriptable and isn't slow as hell, and one to delete files/directories without regard for NTFS file permissions/attributes because I don't like being told I'm not allowed to delete files on my own computer.
>>
ruby vs python vs perl

which should i learn to replace bash shell scripting for more power?
>>
>>61877887
Ruby is great for Unix scripting, it's essentially a better perl. Has less libraries though.

Python has a shit ton of useful libraries of greatly varying quality from 10/10 to utter crap.

Perl is write-only programming language and is essentially Unix duct tape. A lot of libraries as well, but it's losing momentum compared to Python and even systems like Node.
>>
>>61877882
What did you use to find the duplicates, MD5?
I remember trying to do that years ago, but it was slow a fuck.
>>
>>61877861
I've never heard people talking about that before. I guess it is because it is not an ansi c thing
>>
>>61877839
That's still pretty much the process. You know each step, you can look up how to do them.

Splitting strings means walking through the string, keep an index at where you start, advance until you find the next token you want to split on, copy between the current location and the previous index into the output list, and advance both indices to the same place. It's annoying if you're used to more robust string operations being part of the language but it's nothing to get intimidated by.

For token classification you can use a regex library or it's simple enough that you can do it yourself, you only need to recognize quotes, numerics, and parens to get something off the ground.

It'll be a lot of wrestling with C but it's the best way to learn.
>>
>>61877879
https://sourceforge.net/p/sbcl/sbcl/ci/master/tree/src/runtime/runtime.c
>>
>>61877960
its part of C99 and optional in C11

it's not really used since unbounded stack storage isn't usually a great idea
>>
>>61878000
do you happen to know if C Programming: A Modern Approach talk about this kind of thing? I was looking for a book to get to know more about how C works and I feel like I'll be missing some features if I get C Programming Language
>>
>>61877960
>>61878000
I use them quite often. They shouldn't be used for unbounded and untrustworthy input, though.
There are many situations where you can reason about the max length of the array and safely use them, giving you much more performant code.
>>
>>61877950
Yeah, it seems fast enough. I can search 280MiB across 1,958 files and 264 directories in ~1.5s. The hashing itself is about 300-400MiB/s. I experimented with some other hashing functions but couldn't get a significant speed increase and MD5 is simple enough for me to write my own implementation for, which probably helps with any licensing issues if I were to ever release the program as well as just the fact that it feels nice to write everything yourself.
>>
File: lol.png (6KB, 240x184px) Image search: [Google]
lol.png
6KB, 240x184px
>>61877950

Use CRC32. If it detects duplicates, use SHA1 or MD5 on the duplicates to re-confirm.

Ya dig?
>>
>>61878152
>>61878246
I don't know how I managed to fuck up a simple program like that. It was taking 500 ms to compare two relativity small files.
Maybe I will give it a try again when I've got some time.
>>
>>61875133

In C how do I get the program to read one character from standard input and discard any others that are entered? I'm trying to do a simple y/n loop to continue without it sperging out if you enter more than one incorrect entry at a time.
>>
>>61878246
With modern CPUs (anything from the last 10 years) I imagine you're probably being bottlenecked by how fast you can read the data rather than the speed of the hash calculation, even on an SSD.
>>
>>61878342
with a while loop
>>
>>61878342
Read a whole line, ignore the rest of it and use the first character.

You have to consume the extra characters in order for them not to get fed into your next std input usage.
>>
>>61878432
Or validate based on the whole line, your choice. But the point is you have to consume the other characters.
>>
>>61878432

Aite I got it so getchar() then (ch=getchar()) != '\n'?
>>
>>61878446
Yep, or you can use fgets to do it automatically. Keep in mind fgets puts the newline into your read string.
>>
File: 884142.gif (52KB, 280x438px) Image search: [Google]
884142.gif
52KB, 280x438px
>>61878496
>fgets
HAHAHAHAHA
>>
>brian kernighan is left handed
>>
what are the most mystical, ethereal programming languages? scheme? haskell?

also, why does /dpt/ hate rust? it was the most loved language on stackoverflow

https://insights.stackoverflow.com/survey/2017#most-loved-dreaded-and-wanted
>>
>>61876628
>because I'm kind of used to pass-by-reference in sepples
Sepples is no different, retard.
>>
>>61876818
The best way to get better at C is to learn another language and then come back to C.
>>
The average /wdg/ poster gets more stuff done than /dpt/ combined!
>>
>>61878677
>/wdg/
>>>/reddit/
>>
>>61878532
What's your solution?
>>
why are programming books so expensive?
>>
>>61878722

College textbooks.
>>
File: 478895.jpg (40KB, 303x566px) Image search: [Google]
478895.jpg
40KB, 303x566px
>>61878719
Faggots.
>>
>>61878750
Stupid frogposter
>>
There is literally nothing wrong with programming in Python and anyone who disagrees is a pseudo-intellectual.
>>
>>61878536
>tfw right-handed brainlet
>>
>>61878835
>abysmal performance in general
>no TCO
>can't use assignment inside expressions
>conditionals can't be used as lvalues
>no native ropes
>no native support for O(1) array slicing
>>
>>61878942
>conditionals can't be used as lvalues
That's a good thing. Doing so results in poor, unclear code.
>>
>>61878942
also, __dict__
>>
I just learned that in C the assignment operetion returns a value so I can do
a=b=c=d=e=f=g=10
>>
trying to learn c.

Can someone tell me what wrong with this, other than possible shit coding practices?
#include <stdio.h>
const int CONVERSION = 60;
const float DEC = .01;
int main(){
int begin_min, hour, ans_min, mod_min, temp;
char user_min[3];

printf("Enter mins: ");
fgets(user_min, sizeof(user_min), stdin);
sscanf(user_min, "%d", &begin_min);

hour = begin_min/CONVERSION;
mod_min = begin_min%CONVERSION;
temp = mod_min*.01;
ans_min = temp * CONVERSION;

printf(" Answer is %d hour and %d mins", hour, ans_min);
return(0);
}
>>
>>61875195
I would like a Big Mac, Pepsi and fries.
>>
>>61878952
way to not respond to everything else I said. everyone who uses python does the exact same logic except uglier, setting the assigned expression outside an if and then using if statements for each one. because they have to, thanks to guido's enlightenment.

other problems include not knowing statically if basic property accesses have side effects, an issue shared with several other languages.
>>
>>61878966

Increased your buffer size because its not like you are strapped for memory.
Your conversion also is wrong and you only need to take the mod_min as your seconds. I think the following is what you want.
Also, you want to specify main as taking a single void parameter. Not specifying any parameters in C actually means something different (okay in C++ though).

#include <stdio.h>

const int CONVERSION = 60;

int main(void) {
int begin_min, hour, mod_min;
char user_min[32];

printf("Enter mins: ");
fgets(user_min, sizeof(user_min), stdin);
sscanf(user_min, "%d", &begin_min);

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

hour = begin_min / CONVERSION;
mod_min = begin_min % CONVERSION;

printf(" Answer is %d hour and %d mins\n", hour, mod_min);
return 0;
}
>>
>>61878633
really?
that seems counter-intuitive
>>
who the hell thought Hy was a good idea?
>>
>>61879029
So was my issue (besides the incorrect conversion) was that the array was too small?
>>
>>61879172
>>61879029
wowowow im retarded, i essentially tried to do what the modulas does already
>>
>>61877808
I write a different FizzBuzz solution every week in Scheme.
>>
>>61879200
nvm im triple retarded i haven't done remainders since elementary.
>>
Continuing my quest through all the models in our simulation. Currently making sure our atmosphere model isn't retarded.
>>
>>61879211
you too!?
>>
File: 000021-Twitch.png (89KB, 164x265px) Image search: [Google]
000021-Twitch.png
89KB, 164x265px
>>61879303
(spoiler: it does)
>>
>>61879312
Yes, wrote one using macros today.
>>
>>61875159
pandoc
idris
agda
>>
>>61879315
i hate it when my model does retarded too
>>
>>61875159
https://github.com/jameysharp/corrode
>>
>>61879571
no hablo englando
>>
>>61879303
Whatcha simulating?
>>
>>61879689
Guided bombs. Most of the sim was developed by a bunch of GNC monkeys so we're having to go through and fix all the fuckery.
>>
File: sad_wojak.jpg (61KB, 535x577px) Image search: [Google]
sad_wojak.jpg
61KB, 535x577px
>>61878536
>ywn be left handed
Why is being left handed the master race?
>>
what are classes used for in c++?
>>
>>61879827
to encapsulate state and state change of a particular type of object
>>
>>61879827
is this your first time programming?
>>
>>61879827
job security
>>
>>61879860
yes

is writing classes as projects something great to do in order to learn programming? seems like a good first stop.
>>
>>61879877
do basic procedural programming before you even think about OOP
>>
>>61879887
This. Eventually you'll start writing things complex enough that classes and such become the natural next step. They're not really a good starting point.
>>
>>61879887
>>61879921
Okay. Gonna write something and post it when I'm done to get a rating.
>>
>>61879877
OOP in the modern context is a pretty tried-and-failed concept for the most part. It's only useful in huge companies where swaths of low-credential employees that don't collaborate efficiently need to be protected from one another.
Learn basic procedural programming first, maybe something like C or Python. Then some basic functional after that.
>>
I have to make an algorithm that takes a dictionary.txt file with a list of words separated by new lines and find the anagram that occurs the most.

It has to be O(M N) complexity, so using radix sort with counting sort I can achieve this.

Could anyone help me with how they'd do it? I'm struggling to get a grasp on the logic behind it as a sorted list will put all anagrams next to each other but they won't have been counted...
>>
>>61879877
oop being a data abstraction technique, it shouldn't come first
>>
File: fedora.jpg (40KB, 400x400px) Image search: [Google]
fedora.jpg
40KB, 400x400px
>>61879573
Do you wear a fedora too?
>>
>>61879938
>>61879921
>>61879887
#include <iostream>

using namespace std;

int addition(int a, int b);


int main()
{
int a, b, product;
cout << "Enter 2 integers" << endl;
cin >> a >> b;

product = addition(a, b);

cout << "product: " << product << endl;

return 0;
}

int addition(int a, int b) {
return a * b;
}


Am I ready yet or should I just continue with increasing complexity?
>>
>>61880028
>int addition(int a, int b)
>multiplies
???
Also keep doing more, this is basic shit.
>>
>>61880051
oops did it too fast i guess. and okay. what should I do?
>>
>>61879965

Rough pseudo code for the idea. Use a dictionary with a default value of 0 (i.e. a defaultdict in python).

m = defaultdict()
max_entry = 0
max_word = ""

for word in words:
w = sorted(word)
m[w] += 1
if m[w] >= max_entry:
max_word = w
>>
>>61880093
need to set max_entry along with max_word but i think you get the idea
>>
>>61880064
Make a game of tic-tac-toe.
>>
>>61880093
Can't use dictionary because it's worst-case retrieve and input is O(n) when every value is indexed at the same hash :(
>>
/g/uys its raining im excited
>>
>>61875520
>Trying to wrap my head around how C handles headers.
C handles headers (and all includes, the extension does not matter) by simple text concatenation. It simply adds the stuff from the included file right on the line it's included at. For instance, let's say we have two files, a.h and a.c:

/* a.h */

int
do_something()
{
return 0;
}


/* a.c */

#include "a.h"

int main(int argc, char **argv)
{
return do_something();
}


If we compile an object file with "a.c" as the source, it will actually look like this after the preprocessing:

int
do_something()
{
return 0;
}

int main(int argc, char **argv)
{
return do_something();
}


There's no magic there, just code being added to where ever you asked the compiler to add it.
>>
>>61880136
This is the simple part, it becomes a headache when you start worrying about linkage.
>>
What does ERROR_H *actually* define in a header file, like below?
#ifndef ERROR_H
#define ERROR_H
/* eprintf.h: error wrapper functions */
void eprintf(char *, ...);
char *estrdup(char *);
void *emalloc(size_t);
void * erealloc(void *, size_t);
void setprogname(char *);
char * progname(void);
#endif
>>
>>61880110
how would i go about doing that?
>>
>>61880163
It defines the symbol for the preprocessor with no value. Any substitution later will be empty but the only important thing for a header guard is that the symbol is defined.
>>
>>61880163
That's an include guard. The value of the define doesn't matter, all that matters is that it is actually defined. If it is, then the ifndef directive will skip over the body of the header file and avoid duplicate-definition errors in case the header is included a second time.
It's a common pattern, sometimes the #pragma once directive is used instead though.
>>
>>61880177
That's for you to find out. You know how to read text, you know how to print text and you should know some looping and conditional constructs. That's enough to implement the rules of a simple game like tic-tac-toe.
>>
>>61880155
Only if you make it unnecessarily complicated by declaring everything in different files. Just remember that since its all simple string concatenation, you can include a file anywhere, not just at the top of the file (for example, after having defined your data structures).

Generally I think people have a tendency to keep their source files unnecessarily small and that leads to those headaches you're referring to, not to mention actual performance issues of not being able to inline some functions for instance, simply due to bad project structure.
>>
>>61880123
a hashmap is amortized O(1), this doesn't matter and i don't think you should care about it, you can't do any better
>>
>>61880125
/g/uys there is lightning now i dont know what to do
>>
>>61880125
>>61880303
it's pretty dull sunny weather here, trade?
>>
>>61880181
>>61880186
How come when I try to do an empty define in a function it prints an error?
#include <stdio.h>

#define HELLO

int main(int argc, char *argv[])
{
printf("%d\n", HELLO);
return 0;
}
>>
>>61880407
After preprocessing, the file will look like this.
printf();
// other definitions from stdio.h.

int main(int argc, char *argv[])
{
printf("%d\n", );
return 0;
}

You can't have an empty argument like that.
>>
>>61873052
I see. I agree that I'd like more of that. Perhaps not for a beginner book but it's certainly a very important step in learning software.
Find some open source Java project and look into it. Start with something small and gradually work up to enterprise Java.
>>
>>61880327
no sorry i live in a desert this water needs to last us until winter its just very overwhelming sometimes
>>
I'm trying to submit some java code to an online thing as homework, but the thing doesn't accept the format I give it, saying
***Runtime error***
Error: Could not find or load main class XXX

regardless of what I name the main class "XXX". Since I'm just entering the code from the .java file, I guess it doesn't know what the main class should be called. If I try just entering the code within the class then it tells me I've got invalid syntax, so I know I'm nearly there, it's just getting hung up on the class name. In this case, is there some simple workaround or default name for the main class I could try? I'm not expecting a thorough tutorial or anything, just for someone to clue me into something stupid that I've probably missed.
>>
alright Cfags

https://github.com/esmil/musl/blob/master/src/internal/syscall.h#L42

how the FUCK is this macro counting the number of arguments and selecting the right syscallN function to call?

this is pure wizardry
>>
So how do we fix some of the type declaration syntax in C?
Here are some changes I think would be good.
int[] arr; //instead of int arr[]
int[5] arr; //instead of int arr[5];
int* a, b, c; //a, b and c are of type int* instead of *a being of type int.
int a, b, *c //is a compile error now

int*()(int, void*)* fp; //Not really sure about this syntax

The only thing I don't really know a nice syntax for is function pointers without introducing a new keyword
>>
>>61880774
>
#define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0)
#define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0)
#define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0)
#define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),0,0,0)
#define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),0,0)
#define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),0)
#define __syscall_cp6(n,a,b,c,d,e,f) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))


Ah yes, C is action.
>>
File: fragzeichen2.png (174KB, 562x389px) Image search: [Google]
fragzeichen2.png
174KB, 562x389px
>>61875133
Is there a super-minimal, modular version of TeX that can be easily embedded with one's preferred packages?

I've made what I think is a really useful program for normies, but it's handicapped by the fact that it depends on an extant LaTeX installation. It'd be really nice if I could just distribute a standalone binary.
>>
>>61880793
>Is there a super-minimal, modular version of TeX that can be easily embedded with one's preferred packages?
Yes. Read the pdf made by Donald. He explain everything.
>>
>>61880774
>>61880791

I mean this:

#define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0)
#define __syscall_cp1(n,a) (__syscall_cp)(n,(long)(a),0,0,0,0,0)
#define __syscall_cp2(n,a,b) (__syscall_cp)(n,(long)(a),(long)(b),0,0,0,0)
#define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,(long)(a),(long)(b),(long)(c),0,0,0)
#define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,(long)(a),(long)(b),(long)(c),(long)(d),0,0)
#define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e),0)
#define __syscall_cp6(n,a,b,c,d,e,f) (__syscall_cp)(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e),(long)(f))

#define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__)
#define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__))


how the hell does it count arguments
>>
>>61880778
>So how do we fix some of the type declaration syntax in C?
C needs no fixing.
>>
>>61880821
#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,)
#define __SYSCALL_CONCAT_X(a,b) a##b
#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b)
#define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)


It's a clever trick I have to admit.
>>
>>61880778
I say we leave it as it is considering it makes complete sense.
>>
>>61880778
This is wrong because
int[3][6] foo;
is indexed as
foo[5][2];


>>61880889
Returning a function pointer is a nightmarish clusterfuck.
>>
>>61880876
can you explain how it works
>>
>>61880926
You didn't really offer any improvement for function pointers. In fact, I think you made it more ambiguous for more difficult function pointers.

>>61880927
Here's how I see it:
#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,)


__SYSCALL_NARGS("hello") becomes __SYSCALL_NARGS_X("hello",7,6,5,4,3,2,1,0,)
and with named arguments: __SYSCALL_NARGS_X(a="hello",b=7,c=6,d=5,e=4,f=3,g=2,h=1,n=0,), so the result of this macro is 0 since n=0

__SYSCALL_NARGS("hello","world") becomes __SYSCALL_NARGS_X("hello","world",7,6,5,4,3,2,1,0,)
and with named arguments: __SYSCALL_NARGS_X(a="hello",b="world",c=7,d=6,e=5,f=4,g=3,h=2,n=1,...), so the result of this macro is 1 since n=1

That about sums it up.
>>
>>61880960
At a guess I'd choose a style like
int(int, int) fptr;
to declare a function pointer but I'm not sure if that's any better. I haven't thought it through.
>>
>>61880984
I think that with something like this you'll run into clearly ambiguous syntax with pointer to function that returns pointer to function that returns pointer to function.
>>
>>61881010

int i;
char c;
short s;
double(int)(char)(short) fptr = getFptr();
double(char)(short) fptr2 = fptr(i);
double(short) fptr3 = fptr2(c);
double d = fptr3(s);
>>
>>61881072
Now you're asking for way more than just a new syntax for function declaration.
>>
>>61881085
>>61881072
And in addition to that, you haven't even demonstrated a function that returns a pointer to function. All your functions return double and you just used your new feature you came up with that creates a function that returns double from another function that returns double.
>>
>>61881072
You misunderstand what I'm trying to express here.
a value of type
double(int)(char)(short)
is a function pointer that takes an int and returns a function pointer which takes a char and returns a function pointer which takes a short and returns a double. In other words:
int i;
char c;
short s;
double(int)(char)(short) fptr = getFptr();
double d = fptr(i)(c)(s);


This is all speculative shit I don't really know what I'm doing. I'm not the original person who complained about C declarator-style syntax.
>>
>>61881085 >>61881103
not >>61881072
but like I said in >>61880778 function pointers are just hard to think up a new fitting syntax for.
>>
>>61881146
Yeah, and my point is suggested "improvements" to C are not actually improvements at all, since what we have now makes no less sense than your suggestions.
>>
>>61881137 is directed towards >>61881085 >>61881103

I dunno, it makes sense to me.
>>
>>61881137
>>61881195
I know perfectly well what you're doing. You're suggesting the way Haskell handles function arguments. Calling a func(a,b) with just one argument creates a new function, func(b). There are plenty of reasons why this has no place in C, but that's not even the point. A function that returns pointer to the function is not what you are suggesting. A function that accepts 2 arguments can as a result of its execution return a pointer to a function that accepts 10 arguments.
>>
>>61881231
I don't know Haskell and have only a vague idea of functional programming concepts. For me this is just a novice with a thought experiment.
>Calling a func(a,b) with just one argument creates a new function, func(b)
No, there isn't currying or partial application. A function call would be complete just like in C,
void(int)(int)
requires two distinct calls and
void(int, int)
requires one. Nothing changes but the syntax for types.
>>
Came back from work a few moments ago. Rate my 9th C++ program.
#include <iostream>
#include <cstdlib>
using namespace std;

int generate_random_value()
{
return (rand() % 100) + 1;
}

int get_int()
{
int result;
cin >> result;
return result;
}

/*
* Returns 1 if y, else 0
*/
int get_yn()
{
char input;
cin >> input;
if (input == 'y' || input == 'Y') return 1;
else return 0;
}

void check_loop(const int determined_val)
{
cout << "Cheat: it's " << determined_val << endl;
cout << "Enter your guess [1-100]: " << endl;
while (true) {
int response = get_int();

if (response > determined_val) {
cout << "Too big!" << endl;
continue;
} else if (response < determined_val) {
cout << "Too small!" << endl;
continue;
} else if (response == determined_val) {
cout << "Correct!" << endl;
break;
} else {
cout << "Error detected, exiting..." << endl;
exit(0);
}
}
}

int main()
{
cout << "Welcome to the number guessing game. " << endl;
while (true) {
int random_value = generate_random_value();
check_loop(random_value);
cout << "Do you wish to continue? [y/N] :";
if (get_yn() == 0) {
break;
}
}
return 0;
}
>>
>>61881300
All right, I did misunderstand then.

So
void(int,int,int,int,int,int,int,int,int,int)(int,int) func

would be a function that accepts 2 arguments and returns a pointer to a function that accepts 10 arguments (returning void). I'll think about it.
>>
>>61881338
What is your current occupation?
>>
>>61881393
employed haskell programmer
>>
>>61881363
It's the other way around, actually. It accepts 10 arguments and returns a fptr that accepts 2 arguments.
int i;
void(int,int)(int) fptr;
fptr(i, i)(i);

I still think that specifying the types based on how you use them is a good idea. It talked about how it gets confusing with arrays here >>61880926 if you do it in a "dumb" way by just popping off the right hand side rather than making the declaration match the usage like in C.
You'd declare a pointer to int as
*int ptr;
to
int* ptr;
too.
>>
>>61881393
I work as a bartender
>>
>>61881338
be more consistent with bracketing
>>
>>61881462
I thought I was following the K&R style...
>>
>>61881474
you are. don't listen to that anon
>>
>>61881231
not >>61881137 but I assume it works like:

double first(short, int) {
return 1.0;
}

double(short, int) second(char, int) {
return &first;
}

double(short, int)(char, int) third(short, char, int) {
return &second;
}

int main(int argc, char *argv[]) {
int i1, i2, i3;
char c1, c2;
short s1. s2;
double(short, int)(char, int)(short, char, int) fptr1 = &third;
double(short, int)(char, int) fptr2 = fptr1(s1, c1, i1);
double(short, int) fptr3 = fptr2(c2, i2);
double value = fptr3(s2, i3);
double value2 = fptr1(s1, c1, i1)(c2, i2)(s2, i3);
}


>>61881409
Your way makes zero sense.
>>
>>61881532
I don't think you declare a function pointer like that.
A pointer to first would look like
double (*fptr)(short, int);
>>
>>61881559
it's speculating about an alternative.
>>
>>61881565
My bad.
>>
>>61881409
Right. That way you declare the function and use it with same order, func(10 args)(2 args).
>>
>>61881565
>2017
>still adamantly refusing to use decent syntax because it's from type theory and you hate academics

double -> (short, int)


(char, int) -> (double -> (short,int))
>>
>>61881585
whoops

(short, int) -> double

i got confused because C function type syntax is backwards
>>
File: 1502126194359.png (827KB, 858x1200px) Image search: [Google]
1502126194359.png
827KB, 858x1200px
Here is my first line of code. What do you guys think?
 #define female female(male)/* traps are not gay */ 
>>
>>61881606
You got confused because you are generally just a confused person. My suggestion for you is to get your shit together.
>>
>>61881627
No, I got confused because no sane person would want
output(input)
>>
61881625,

That definitely looks like someone's first line of code.

Anon.
>>
File: 1479883677181.jpg (143KB, 833x696px) Image search: [Google]
1479883677181.jpg
143KB, 833x696px
>>61881643
>>
>>61881637
At some point you have to stop being confused. You may think you have all the time in the world, but that's not actually the case.
>>
>>61881657
What are you even talking about?
>>
>>61880793
#lang racket/scribble
>>
>>61881696
Take your time.
>>
>>61881700
You have a really roundabout way of trying to pretend C has good syntax for function types
>>
>>61881707
Those are levels of confusion that even I did not predict.

>anons are talking about a new syntax for C function pointer type declaration
>this means they must really think C has good syntax for function types
>>
>>61881741
I know, and your proposed syntax is just as bad.
>>
>>61881751
1. It's not mine.
2. You're still a very confused person, even more so after >>61881707.
>>
>>61881771
You are just posting dribble.
It's you who's confused.
>>
>>61881779
A perfect example of dribble is >>61881707.
>>
I've only learned how to ""program"" recently. I made my own version of Conway's game of life yesterday.
>>
File: 1488475745114.jpg (144KB, 600x678px) Image search: [Google]
1488475745114.jpg
144KB, 600x678px
Is there a way to get instant volume change notifications? I was thinking of setting inotify to watch whatever amixer writes to but it doesn't seem like it writes to a file. I'm probably going to end up writing to a file when I press the volume change keys and watching that instead but I would like a less hacky way if it's possible.
>>
File: cwgol.png (26KB, 842x647px) Image search: [Google]
cwgol.png
26KB, 842x647px
>>61881899
pic related
>>
>>61881934
Looks like HTML+CSS+Javascript.
>>
File: 1275349948732.png (5KB, 429x410px) Image search: [Google]
1275349948732.png
5KB, 429x410px
>>61881948
Ya got me. Hence the quotation marks.
>>
>>61881972
Well, I got nothing against JS. Apart from few very silly quirks, it's a fine language, and HTML+CSS is a great tool for making UI.
>>
>>61881990
undefined is not a fine language.
>>
>>61876049
I haven't done C++ in a while but, for starters, you might want to replace that switch with an array of strings.
E.g:
string get_type_string(monster_t m){
string[] name = {
"ogre",
"orc",
"dragon",
"Giant spider",
"slime"
};

return name[m];
}

Even then, you might want to take that list out of the function and have it be global or in its own header or something.
>>
>>61881996
Are you ok?
>>
Starting off my journey on Scala.
>>
>>61875133
>one sperg's opinions
>"/dpt/ recommended"

Scheme is cool, but irdis and shen are fucking useless, and learning both is even more useless. Irdis is slow with a shitty syntax. Shen isn't all too bad, but it's not necessary when you can just use Scheme in it's place.
>>
>>61882046
I implore you to watch this before making a big mistake.
https://www.youtube.com/watch?v=4jh94gowim0
>>
File: sudk.png (47KB, 850x655px) Image search: [Google]
sudk.png
47KB, 850x655px
>>61881934
Also this, in similar fashion.
>>
File: comfy_merge.png (17KB, 486x899px) Image search: [Google]
comfy_merge.png
17KB, 486x899px
Is my merge sort implementation comfy?
>>
>>61882182
It's not done yet btw, I still want to add function pointer and remove the initial value.
>>
> software engineering, theory and practice, and will include some programming exercises.

How do I prepare for an interview containing questions about "software engineering theory and practice"?

Do they mean OOP?
>>
>>61882182
please stop using pure colors, especially black on white.
Your eyes fatigue faster.
>>
>>61882206
that's yellow
>>
>>61882213
needs to be a little darker though.
>>
>>61882182
Is this acme?
>>
>>61882206

Dark themes are stupid.
>>
>>61882245
It is sam.
>>
>>61882305
bright themes are stupid.
>>
>>61882424
No they aren't. The human system likes nature and nature is full of pale colors, so something you’re going to look at all day is best served if it were also in relaxing shades.
>>
File: bearsuit lain.png (399KB, 762x990px) Image search: [Google]
bearsuit lain.png
399KB, 762x990px
https://scratch.mit.edu/projects/18997849/
>>
>>61882305
This, but I resort to dark themes otherwise I cannot read yellow/red text.
>>
>>61882522
lain is cute
i love lain
>>
>>61882470
>nature is full of pale colors
Nature is also full of dark and saturated colors, as well as J-Pop bright and bold colors.
Whats your point?
>>
File: suicide.gif (312KB, 480x360px) Image search: [Google]
suicide.gif
312KB, 480x360px
>>61882565
>ynw have lain as a gf
>>
>>61882577
>wanting a spaced & depressed gf
no you dont lad, trust me.
>>
How many of you are actual pajeets?
>>
>>61882577
w-what is she doing to that gun
>>
>>61882470
text colors are harder to distinguish with a bright color scheme than with a dark one, making working with it more straining. furthermore, small characters or marks like dots are more difficult to perceive when blurred (through e.g. poor eyesight) on a bright background compared to a dark one.
>>
>>61882522
>lisp
meh
>>
>>61882182
>I'm a big boy who doesn't need syntax highlighting
>>
>>61883020
>I'm a big boy who refuses to take off his training wheels
>>
>>61883047
>making shitty analogies
>>
>>61883047
>I'm a big boy because I refuse to use anything useful that helps me
>>
I have no hands. Can I still be a programmer?
>>
>>61883066
2 foot pedals are enough for machine code
>>
>>61883059
>>61883058
Doesn't constitute arguments. Stay triggered kids
>>
>>61883083
>My posts contain arguments but yours don't because I'm a big boy and you're not
>>
>>61883100
Ask your mom to put a diaper on your head, shit-for-brains.
>>
>>61883121
Nice argument, big boi
>>
>>61883140
>>61883121
>>61883100
>>61883083
>>61883082
>>61883066
>>61883059
>>61883058
>>61883047
>>61883020
Are these my future co-workers?
>>
>>61883155
better fucking start praying
>>
>>61883155
I worked at 3 places so far, and none had people acting like that. There were some assholes but even those were polite.
>>
File: キャプチャ.png (8KB, 520x236px) Image search: [Google]
キャプチャ.png
8KB, 520x236px
>>61883155
What did you mean by this?
>>
>>61883257
He meant he would really dislike for you to be his coworker, a sentiment I happen to share with him.
>>
>>61883277
Don't worry. If you're anything like the average deepeeteér, you probably won't work with me, or anywhere for that matter.
>>
Guys I wanna learn c++ more thoroughly, aside from code academy and solo learn what other books should I read?
>>
>>61883300
More "thoroughly"? C++ Primer (not the one by Prata) is pretty thorough.
>>
>>61883296
I know. I'm the person who wrote >>61883174.
>>
>>61879827
disgusting stateful programming
>>
>>61882522
>>61882565
>>61882577
>Not capitalising the "L"
Damn it. For a second, I was doubting whether her name was Lain for Iain.
I know a few Iains.
>>
File: 1474074445126.gif (295KB, 700x704px) Image search: [Google]
1474074445126.gif
295KB, 700x704px
>>61884476
there is only one lain whom we all love
>>
Does C++ execute all code in a file? Tried to initialize some static members for a class and it forced me to do it outside of the class, worked fine just below it.
>>
>>61884632
I don't know what you mean.
>>
>>61884632
Static members are like namespaced globals.
>>
>>61884632
>Does C++ execute all code in a file
They say that there are no stupid questions, but there are, and this definitely is one of them.
Thread posts: 337
Thread images: 37


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.