/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

youtube.com/watch?v=YnWhqhNdYyk
coliru.stacked-crooked.com/a/0d0928dee44b0e2c
pastebin.com/pzGKFTUF
twitter.com/NSFWRedditImage

not this again

Why dis not work?

std::set TriggerValues(comparator) {values here};

On C, instead of using "else if"s can i just keep using "if"s?
will it yield the same results?

all your if statements will be queried/checked, unless you're returning in the if above it.

I have no idea what you're trying to do

if you have "if p { } else if q { }" then you can't blindly replace this with "if p { } if q { }". what if both p and q are true?

Trying to supply std::set with comparator function which is something like doing strlen string 1 < strlen string2 (const char*)

actually it should be std::multiset

My C++ book said it should work properly but it doesn't, gives syntax error

Is there a book that teaches C++ like it's C (precisely what happens in the memory with various complex abstract constructs)?
Also, for people who already know a lot?

Else if will avoid checking once one comparison is true, with only ifs it will keep checking

this
else if (condition) {
// code
}

is in fact this
else {
if (condition) {
// code
}
}

Hey Sup Forums I need your help, am writing a small pet OS I have a working console I run it on qemu and the key repeat(IE arrow keys and such) is fast as one would expect and the cursor moves fast, but when I run it on real hardware or virtualbox the cursor is slow as shit.
Anyone has any experience on this? I dont really know what to search for in google desu famsenpai

because I was slow, from other threaad.
are you saying std::string isn't dogslow and that you shouldn't favor const char * const over it? I mean, its not as retarded as QString and with SSO in C++11, it can be good but.. on interface boundaries its ideal to not expose an std::string.

internally, if you're using it for identity or as read-only, why not use the const char * const? I'm not telling him not to use a string, but in places where a const char * const will work. I use string/wstring a lot, but I know it can pretty slow for read-only strings.

or are you complaining about where my pointers are?

auto is nice because it doesn't do implicit conversions. so you won't have possible temporaries/copies or have the wrong type. like std::string f = "asdf"; will do. (granted an optimizing compiler will almost always improve this).
but for non-primitives you shouldn't likely ever use = in declaration, but rather uniform initialization std::string f{"asdf"}; // same as auto f = "asdf"s

oh, ofcourse not. but std::string should be passed by reference, not by value in the general case. but there are different use cases (it is c++ after all)

const std::string& // when you want to modifies caller string
std::string const& // read-only, but const char * const is probably better

std::string // a copy but...
std::string&& // this is better, or std::move(your_string)

You're looking for pretty specific answer, I doubt you'll get anything… Add tracing to your codebase so you can see where it's slow? It's something you should be doing anyway, you can't expect to write everything with good performance on first try (as obvious here).

oh.
Initializer list can be given as the first argument to the constructor, so
std::set TriggerValues({values here}, comparator); should work.

Do you know C already?

Well one would expect that it runs fast on real hardware too, am thinking if there's something like a refresh rate for the keyboard controller or something like that.
Like I said, I dont really know what to search for.

Trying as following :

std::set TriggerValues({"Nigger"}, comparator);


It says "Expression expected" near decltype operator for some reason

using Clion IDE

Could anyone post the most updated Pro/g/ramming Challenges image?

google "g programming challenges" and never come back

I even know a lot of C++.

are you a better programmer than your peers?

Do you compare yourself to them?

Then you should know what all of your abstractions are built out of already.

>/dpt/ recommended
There are 0 (zero) anime girls on the picture, therefore, it's not a legit /dpt/ image.

Where from? In many cases I can guess it after a while but it would be nice to learn this in a systematic way. Is there an in-depth book like that?

no
yes

I'm downloading NetBeans. Fucking CLion sucks coming from Visual Studio. Has no proper intellisense-like thing.

Using Linux here, i read that NetBeans gives best VS like experience

qtcreator and kdevelop are pretty nice too. (you don't need to do Qt while using them, either).

>Programming languages involved were C, Go, and Rust.
Youre illiterate i see.
They were compared in 2 of the 3 but i threw in Vibe because its a notable third party lib, even though i have some qualms with it.

How do I redefine a method returning array of parent class objects, to make it return an array of child class objects? It does not convert on the run

What's up with that asterisk after decltype()? Seems ambiguous and sorta funky...

decltype defines what "comparator" function is and asterisk asks it to define pointer to comparator

how is your comparer defined?

with a lambda:
auto comp = [](const int& lhs, const int& rhs) -> bool { return lhs < rhs; };
std::set values{{5,7,3,6}, comp};
for (auto& i : values) { std::cout

bool comparator (const const char* cstr1, const const char* cstr2){
return strlen(cstr1) < strlen(cstr2);
}

const char* const

//fix

double const don't make sense, btw
and char* doesn't define an < operator.
use a string for that. or write your own that handles char[] (or use something like strcmp from c)

I know, fixed double const. But it looks like error is not because of my comparator function, changing it to

bool comparator(std::string &str1, std::string &str2) {
return str1.size() < str2.size()
}

doesn't work. Still says expression expected (near decltype())

Passing std::string instead of &std::string doesn't work either

C is not the same as C++ under the hood. Certain C like expressions don't work the same in C++, I also would imagine their are gonna be weird finnicky differences between asm code generated from a C compiler and code from a C++ compiler and I thought generally with member functions C++ compilers made some sort of weird table to map out calls for specific objects which isn't really comparable to C afaik because C doesn't support oop unless you try to implement it yourself. Also templates and junk aren't really a C thing. (Not counting simple macros)

The poster of the question might enjoy some assembly books and reverse engineering books because a lot of those tend to enjoy picking at C for the sake of learning seeing as jumping between C and asm is a lot better than say Java -> JVM bytecode -> asm. I know AoA talks about its own weird class system but I stopped reading it before that point, Reversing secrets of reverse engineering had some cool parts on C# and I think it had bits on C++ too but I don't really remember it super well. That whole book picks at things from an assembly perspective. (Which makes sense because it's an RE book.)

For templates and stuff I can't be too helpful but it's worth remembering that templates are mean't to be executed before compilation so it's more relevant to like a book on code generators and compilers rather than the lowlevel stuff.

I don't know your types or anything, but I presume:
bool comp (const std::string& lhs, const std::string& rhs) { return lhs < rhs; }

int main() {
std::set values{{"asdf","fdsa","zsdf"}, comp};
for (auto& i : values) { std::cout

I meant to say C++11. but if you're just doing < then you don't need a comparer because std::less is the default.
template<
class Key,
class Compare = std::less, // class set;


if you wanted to be explicit you could do:
std::set values{{"asdf","fdsa","zsdf"}, std::less()}; // you don't need to put std::string in the less brackets in C++14, its implied.)
// and to sort backwards:
std::set values{{"asdf","fdsa","zsdf"}, std::greater()};

It says argument type std::basic_string is not compatible to bool or something like that when i use it this way

youtube.com/watch?v=YnWhqhNdYyk

i wish this was the popular attitude. Or is the title deceptive?

I'm gonna have to watch this for the keks.

I fucking hate that talk so much. If you learn C++ you should know more than the average Python programmer.

This video is retarded. It literally says

>C++ students are too dumb for learning C
>its so advanced, muh pointers
>only teach C++ Pajeet library

c++ != c. That's the point.

thats odd, can you show the comparer and the set (where you're making it..)?

here's an example of the 3 methods I've mentioned:
coliru.stacked-crooked.com/a/0d0928dee44b0e2c

It's actually quite simple.
A module foo can either be a simple source file or a directory with a mod.rs file.
project/
|
+- main.rs
+- foo.rs

or
project/
|
+- main.rs
+- foo/
|
+- mod.rs

I just copied your code and CLion is still bitching. Pretty odd.

well.. can you show the code? I'm leaving soon but I can probably help you fix it. "no expression" sounds like a simple syntax error, in this case.

but if you're just gonna do < then don't bother with the comparers.. set is sorted by default in natural order.
// comp just does lhs < rhs
std::set my_set{{"rsad","asdf","fdsa","zsdf"}, &comp};
// is equivalent to
std::set my_set{{"rsad","asdf","fdsa","zsdf"}};
// because it defaults to doing:
std::set my_set{{"rsad","asdf","fdsa","zsdf"}, std::less()};

but I'd question why you need to use a set instead of std::unordered_set. you can always do std::sort on it later. its faster because each addition/removal doesn't need to be sorted at that point in time.

Yeah, if you lie to people.

There are good points in the talk.

No, if you've actually studied the programming languages and know what you're talking about.

>teaching with an IDE

Holy shit i just installed NetBeans and default font is a fucking cancer. MY EYES, GOD DAMN IT.

How to fix this

>use Go with a postgres database
>trawl the internet for good sql/db libraries
>every retarded """Gopher""" screams to NOT use ORM's, to only use the base sql/db package
>ok, many decent libraries like sqlx
>except they can't handle any fucking mapping involving joins or one to many relationships at all
>hur dr dont use orms ;)

how the actual FUCK are these faggots designing their projects? Don't they use joins at all? Are they running ONE QUERY PER TABLE?

what the fuck Sup Forums

if you're using C99 or later, you're writing illegal C++.
// are these valid C++?
void foo(char bar[10]);
void foo(char bar[static 10]);

// are these the same? (same result)
sizeof('a'); // C
sizeof('a'); // C++

// is this valid in C++?
#include // if you wanna be a pedant
void foo() { clog(0.3); }

// is this valid in C?
int i, j;
(i,j) = 1;

// or the easiest example of valid C, but invalid C++:
struct foo* p;
p = malloc(sizeof(struct foo));

plus a ton of other changes

Then explain this, dimwit:
if (condition) {
// code
} else if (condition) {
// code
} else if (condition) {
// code
}

>trusting faggots in language design
I feel pity for him to be honest.

#ifdef __cplusplus
struct nu_voidptr
{
void *data;

template
operator T*() { return (T*) data; };
};
#define malloc(x) nu_voidptr{malloc(x)}
#endif
where is your god now

if (condition) {
// fuck
} else {
if (condition) {
// my
} else {
if (condition) {
// ass
}
}
}

gladly

>implying that complies

>no windows xp support
What makes people drop old Windows support?
New Visual Studios don't support them?

>macros

Holy crap NetBeans font, what the actual fuck. How can people code using this, what....

my fucking eyes are almost bleeding

What the FUCK is wrong with Java-pajeets?

You literally can't consider yourself better than your peers unless they use the tools you've built.
Until then, you're at best equal to them.

if (condition) {
// fuck
} else {
if (condition) {
// my
} else {
if (condition) {
// ass
}
}
}

yeah :^) but then you still haven't solved that assignment from void* to a type is legal (and commonly used) in C.

VS2013? dropped support for XP. They didn't want to continue to update the crt/msvcrt/libcmt/etc runtimes for it. So you can build it without a standard lib, get the SDK with the _xp tools in it. Or use mingw :)

(its the reason you need to all all those redists with games and shit, c and c++ target a specific runtime because of microsoft's view on ABI..)

please attach the pic

Better cast it just to be safe.

> get the SDK with the _xp tools in it
Do they exist?

You can't talk about C++ in a way that shows that you know what you're talking about without talking in C.

...

I've been starting relating more and more with post Google Pike 2bh

Trying to get fuking octave-mod to work on emacs.

sure. this is the latest version of VS released this week.
but you can search for, eg, vs2015 xp toolset (or v120_xp if you know the version..)

Writing C++ like it's C is how you get some of the worst, most harmful C++ code.

So just the fact you've said this indicates that you are one of those shitty C++ programmers.

isocpp and the core guidelines said to prefer never using new/delete. so I use malloc and free :^)

help not make this shitty?
void parse_obj() {
FILE* obj_file;
obj_file = fopen("bull.obj", "r");
char c;
float v1, v2, v3;
vertArray* ptr_vert;
vertArray* temp_vert_ptr = NULL;
ptr_vert = (vertArray*) malloc(sizeof(vertArray));
int f1, f2, f3;
elemArray* ptr_elem;
elemArray* temp_elem_ptr = NULL;
ptr_elem = (elemArray*) malloc(sizeof(elemArray));
while (fscanf(obj_file, "%c", &c)!= EOF) {
if (c == 'v') {
fscanf(obj_file, "%f %f %f\n", &v1, &v2, &v3);
ptr_vert->v1 = v1;
ptr_vert->v2 = v2;
ptr_vert->v3 = v3;
ptr_vert->p_right = (vertArray*) malloc(sizeof(vertArray));
temp_vert_ptr = ptr_vert;
ptr_vert = ptr_vert->p_right;
ptr_vert->p_left = temp_vert_ptr;
}
else if (c == 'f') {
fscanf(obj_file, "%d %d %d\n", &f1, &f2, &f3);
ptr_elem->f1 = f1;
ptr_elem->f2 = f2;
ptr_elem->f3 = f3;
ptr_elem->p_right = (elemArray*) malloc(sizeof(elemArray));
temp_elem_ptr = ptr_elem;
ptr_elem = ptr_elem->p_right;
ptr_elem->p_left = temp_elem_ptr;
}
}
ptr_vert = ptr_vert->p_left;
free(ptr_vert->p_right);
ptr_vert->p_right = NULL;
unsigned int vcount = 0;
while (1) {
++vcount;//printf("%f\n",ptr_vert->v1);
if (ptr_vert->p_left == NULL) {
break;
}
ptr_vert = ptr_vert->p_left;
}
unsigned int fcount = 0;
ptr_elem = ptr_elem->p_left;
free(ptr_elem->p_right);
ptr_elem->p_right = NULL;
while (1) {
++fcount;//printf("%d\n",ptr_elem->f1);
if (ptr_elem->p_left == NULL) {
break;
}
ptr_elem = ptr_elem->p_left;
}
unsigned int i = 0 ;
float vertices[vcount*3];
while(1) {
vertices[i] = ptr_vert->v1;
vertices[i+1] = ptr_vert->v2;
vertices[i+2] = ptr_vert->v3;
if (ptr_vert->p_right == NULL) {
break;
}
ptr_vert = ptr_vert->p_right;
i += 3;
}

i = 0 ;
int faces[fcount*3];
while(1) {
faces[i] = ptr_elem->f1;
faces[i+1] = ptr_elem->f2;
faces[i+2] = ptr_elem->f3;
if (ptr_elem->p_right == NULL) {
break;
}
ptr_elem = ptr_elem->p_right;
i += 3;
}
}

At least I know what the fuck I'm writing, bloatware fag.

Can someone explain why C functions ceil(x) and floor(x) have double argument and double result and not double argument and int result?

ceil and floor do not convert arguments to integers.
ceil and floor round doubles to their respective whole value

Is that image a meme or should I learn Scheme as my first language?

it's a meme

you could also just install VS on linux

(You)
no shit, I cringe everytime I do something like this..

auto size = image->GetPropertyItemSize(PropertyTagFrameDelay);
auto item = std::unique_ptr(
reinterpret_cast(
malloc(size)),
free);
image->GetPropertyItem(PropertyTagFrameDelay, size, *item);


..needed to reformat that so the ugliness can be seen..

beause the range of double is larger than an int? (what if your inputs are bigger than int?)

Vim.

What language? I'm using vscode on linux for C++ and it's pretty comfy.

Lurking Sup Forums has killed my programming soul. Now I want to be a lawyer.

Why?
Sup Forums helps me learn, desu.

Anyone here that has used Rust that can tell me what the deal is with modules? I am having a hard time understanding what the language specifies as a module. It's not a namespace like in c#/java/php etc etc because it doesn't seem possible to have a module split over multiple files. Both the new and the old books are trash.

There isn't really a legitimate reason to continue supporting a 16 year old OS. That's old enough to have sex with in my state.

Someone already answered, or are you just shitposting?

r8 my shitty memory allocator
pastebin.com/pzGKFTUF

I asked that question in the previous thread and had 0 replies to it.
Just only now saw someone replied to it in this thread.

But If I want to split up stuff in that module into multiple files those files will be different modules.

because I learned Java and /dpt/ constantly tells me that Java is a meme

Wow, shame you used your one and only programming language brain slot. If only you could expand it and add a second one.