/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

ghostbin.com/paste/4pgfs
pastebin.com/sNc0awyw
sqlfiddle.com/#!9/48057/1
repl.it/J9no/0
twitter.com/SFWRedditVideos

muslims

Asuka worst girl

>tfw asuka will never peg you while you program together

Is there anything specific that you need to consider when designing a program that intends to have multiple frontends? For example something like transmission-bt, it has a cli, coacoa, gtk, qt, web, and maybe more frontends. Is this just a result of having fine grained functionality in the core library?

I just installed a syntax highlighting vim file, but the syntax rules don't automatically load when I open the shader source.

I put
au BufNewFile,BufRead *.frag,*.vert,*.geom setf glsl
In my .vimrc

Doing :set syntax=glsl works though.

...

(you)

fn why(s: String) -> String {
s.split('\n').join('\n')
}

error: no method named `join` found for type `std::str::Split

trying to get this regex to work (C++11)

complex_integer = std::regex("(-)?([0-9])+(\+|-)+([0-9])?(i)+");


regex_error caught: regex_error

The expression contained mismatched brackets ([ and ]). // no it fucking doesn't


it works on regexr.com

escape your '-'?

What did you expect from a language that makes even the most simple things overly complicated?

didn't work

What's the standard way to do this in C++11?
Cloudflares protection is a peice of shit and won't let me post this inline.
ghostbin.com/paste/4pgfs

That only works in gcc.
I have a bunch of constant chars that I just want to turn into a constant string (const char*) during compile time so that it's embedded in the binary. Looking for any standard way to turn constant chars into a constant string, I'm going crazy with this.

Going to try to walk through this with you cuz I'm bored as fuck.

First things first, you don't want ([0-9])+, you probably want ([0-9]+), unless you want capture groups for every individual integer.

Struggling through the K&R book.

I'm writing a recursive version of 'reverse(string)',
/* EXERCISE 4.13 - Write a recursive version of 'reverse(s)',
which reverses a string, s, in its place */
#include
#include

void r_reverse(char* s, int ind, int end_ind)
{
char temp = s[ind];
if(ind != end_ind)
{
int other_ind = strlen(s) - ind - 1;
printf("S[ind] = %c\t", s[ind]);
s[ind] = s[other_ind];
s[other_ind] = temp;

printf("S[ind] = %c\t\n", s[ind]);

r_reverse(s, ind+1, end_ind);
}
}

void reverse(char* s)
{
r_reverse(s, 0, strlen(s) / 2);
}

int main()
{
char input[] = "Reverse Me!";
reverse(input);

printf("%s\n", input);
}


This code runs fine and works as is, but when I do
char* input = "Reverse Me!";
I get Bus Error: 10

What's going on?

String literals are not modifiable.
Use char input[] = "Reverse Me!"; to make a new string that you can actually change.

alright...

we're talking about a complext integer, having a form a+bi

I'd probably recommend capturing negative a's within the first group.

(-?[0-9]+)

next, there will be a single operator, + or -

([-+])
(I like having an operand character class than your or because it's cleaner. Why you were allowing for multiple operands, I'm not sure.

next is the imaginary number

which is same as above, but with a necessary 'i'
(-?[0-9]+i)

yielding:
(-?[0-9]+)([-+])([0-9]+i)

if you want an optional imaginary component, then:

(-?[0-9]+)([-+])([0-9]+i)?

you follow?

In what way is a string literal not what you want here?

Stop writing buffer overflow-prone code. Ideally use a decent modern language invented after memory protection, but if you have to use C, then check the boundaries of your fucking strings for crying out loud (send the size as an argument).

Thanks

So... Is the difference between char* and char[] that one's a string literal?

I don't know how you mean. I want whatever will work, essentially I just need to compose a constant string from character constants.

>std::regex

that one compiled but didn't work

I'm pretty sure this fucking std::regex shit is broken

Why's is that generic looking lesbian anime girl doing a backflip? What does she got to do with programming?

stop posting this, it's not even completely correct.

for what input?

Who are you quoting?
If you don't tell me who you're quoting I'm going to have to ask you to leave.

ADTs are superior to classes because there's nothing you ever need a class for whose purpose wouldn't be more easily served by sticking enums, unions, tuples, data structures, and wrappers together like legos, and ADTs are pretty much that, except the syntax for each such layer of type sophistication is less idiosyncratic, and also they're conceived in terms of functions over type rather than in terms of language built-ins

>So... Is the difference between char* and char[] that one's a string literal?
String literals live in read-only, static storage.
When you assign a string literal to a pointer, think of it like you're doing this:
static const char __hidden[] = "Reverse Me!";
char *input = (char *)__hidden;
But when you assign it to an array, it makes a new local copy which you can do whatever you want with.
static const char __hidden[] = "Reverse Me!";
char input[strlen(__hidden) + 1];
strcpy(input, __hidden);

What is the point of this shitpost?

I fall in love with visual studio code a little more every day. Those fuckers finally did something right.

Maybe I'm missing the point of your example, but a string literal is literally a constant string of characters. Why the macro?

That makes a lot more sense.

Thanks!

I'm trying to format __DATE__ and __TIME__ like this and it's killing me.
#define TIMESTAMP { __DATE__[7], __DATE__[8], __DATE__[9], __DATE__[10], '-', MONTH[0], MONTH[1], '-', __DATE__[4], __DATE__[5], '-', __TIME__[0], __TIME__[1], '-', __TIME__[3], __TIME__[4], '-', __TIME__[6], __TIME__[7], '\0' }

I need the timestamp to be in there at compile time and in that format. MONTH is defined elsewhere but it just takes them month portion of __DATE__ and turns it into a decimal represented as a 2 char string "01"-"12".

I'd like to kindly ask you to leave this thread
Bullying belongs in

I should have stated the format
YYYY-MM-DD-HH-MM-SS
2017-07-19-07-34-00

Stop shitposting please, onegai desu ne

>onegai desu ne
cringe

This seems like a gross misuse of the C preprocessor. Just use strftime and strptime.

y-yamete!! Bok..watashi wa kakoii desu ne

I need the resulting string to be built into the binary, so it has to be there at compile time, I can't do it at runtime.

those would be runtime timestamps, not compile-time ones

rip Akari boobs, gone but not forgotten

>So... Is the difference between char* and char[] that one's a string literal?
No, you can assign it to either.
The real difference is that a char [] is a statically allocated buffer of known size and the memory it points to lives and dies with the function where it was declared, whereas a char * is just an address, with no information available as to the size of the buffer pointed to, where and how it was allocated, or if there even is one (as opposed to being a "dangling pointer" into nowhere).

Isn't it simple enough just to write it as a constant character array?

eg. const char timestamp[] = { '1', 2', '3', '\0' }

fn why(s: String) -> String {
let lines: Cow = s.split("\n").collect();
lines.join("\n")
}[\code]

It is dumb. Alternatively, check out the itertools crate which has what you're looking for.

You would feed it into strptime(__DATE__" "__TIME__, "%b %d %Y %T", tm) or whatever, and then write whatever format you want using strftime.

Is there any reason you need that particular format?
Also, I'm curious as to how you possibly got MONTH completely at compile time.

this would incur a runtime overhead for no real reason

all input

That works but it's not what I need, I need a pointer to a constant string, not a constant character array. When I use an array the compiler is complaining about unresolved external symbols, I'm trying to export the timestamp as a data object on a dynamic library.

I'm aiming for the ISO standard format, this dash format is just for example as it's close enough.

#define MONTH (\
__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? "01" : "06") \
: __DATE__ [2] == 'b' ? "02" \
: __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? "03" : "04") \
: __DATE__ [2] == 'y' ? "05" \
: __DATE__ [2] == 'l' ? "07" \
: __DATE__ [2] == 'g' ? "08" \
: __DATE__ [2] == 'p' ? "09" \
: __DATE__ [2] == 't' ? "10" \
: __DATE__ [2] == 'v' ? "11" \
: "12" \

failing at sql....

combine tables a, b, c
select a specific attribute from a column.
Then do a second query that combines them again
selects a different attribute from the same column.
Then ultimately returns a list of those that have matching sub attributes....

post a couple examples, user, just to make sure.

I gcc'd with the -std=c++11 and it's working for me

If you know of a c++ code bin thing, I'll post source. Sup Forums is giving me fits about it.

It was fucking garbage

jdoodle.com/a/4sJ

>I need a pointer to a constant string
>not a constant character array

There's no difference between those two things.

Your actual problem sounds like the symbol isn't being exported from the library, which is inherently gonna be a compiler-specific problem. Also bear in mind if you make it a macro (which is inline) the date will be the compile date of the code using the header, not the compile date of the dynamic library.

Hello /dpt/
Does anyone have any good resources to learn the basics of C memory management? I slept through most of that chapter in my programming class.

As much as I hate recommending non-standard shit, a possible solution you could do is
#define _XOPEN_SOURCE // for strptime
#include
#include

/*
* We use separate storage, so we can modify the timestamp in the constructor,
* but not through 'timestamp' itself
*/
static char timestamp_[32];
const char *const timestamp = timestamp_;

__attribute__((constructor))
static void set_timestamp(void)
{
struct tm tm;
strptime(__DATE__" "__TIME__, "%b %d %Y %T", &tm);
strftime(timestamp_, sizeof timestamp_, "%FT%TZ", &tm);
}

int main()
{
printf("%s\n", timestamp);
}

read the chapter?

>implying I bought the book

rate this list

java
- kotlin
python
haskell
swift

/t/?

I am doing it like this

pastebin.com/sNc0awyw

Is there a way I can use C without the cluster fuck dumb shit C preprocessor?

This is my terrible attempt at this, using a somewhat contrived dataset.

sqlfiddle.com/#!9/48057/1

So what I would want to do is compare houses in two cities ('lorum' and 'ipsum' in this specific case) and return only those where the 'color' and 'roof' match.

This would be a correct response (no particular order)
100, fubar, lorum, black, steeple
562, fubar, ipsum, black, steeple
104, fubar, lorum, orange, flat
564, fubar, ipsum, orange, flat

Not without making things a thousand times more complicated

Is there like a version of C that is like Go but without gc?

Realistically, the only parts of the C preprocessor that you actually need for practical use are #include and the #ifndef guard. C macros are something you can do without.

>and the #ifndef guard
Not even that.

Yeah, but macros make C seem like a hacked together piece of crap because you have to process a file multiple times.

>There's no difference between those two things.
There must be some difference, the linker gives me an error when using an char array vs a char*. I export a version string that's static enough to be an actual literal const char* Version = "0.1.0"; if I were to do const char Version[] = {'0', '.'...}; that won't export. Specifically I get this as a linker error: "unresolved external symbol Version".
I have Version exported via a .def file Version = Version DATA
It works as expected in external programs when I use a string literal and I want the same functionality but with a build timestamp.
>Also bear in mind if you make it a macro (which is inline) the date will be the compile date of the code using the header, not the compile date of the dynamic library.
I don't understand, wouldn't the header always be out of date since it's using the __DATE__ macro? As long as that's true the build date on the library should be correct when I build it, no?

Unfortunately it has to be standard, I intend to migrate to another compiler later.
If I could use non-standard things the original example works fine in gcc
repl.it/J9no/0
^This is exactly what I need but done standard.

Why not just use cgo, writing Go for the majority and C where you need to manage your own memory.

#ifndef is part of the C standard
#pragma once is not

If you want to make a header file that will be reused across multiple files, it is necessary that you use the preprocessor to prevent it from being included twice by the same file. The correct way to do this is with #ifndef.

Except handling updates. I get each update twice.

trying to help, but I'm having trouble with getting this to jive with my GCC and I don't want to downgrade to 4.

The regex I gave you should be right, though. Have you tested the link I gave on you machine?

jdoodle.com/a/4sJ

Why does someone just make a more modernized version of C? Like, C with some modern conveniences, like packages/modules.

>Why doesn't someone just do the right thing
Stop that.

It worked

idk mane

What are you smoking? I did not mention #pragma once anywhere.

The only alternative to #ifndef guards is #pragma once. You did not need to mention it for it to be implied.

The only alternative to #ifndef guards is not using them at all as you probably do not need them.

>If you want to make a header file that will be reused across multiple files, it is necessary that you use the preprocessor to prevent it from being included twice by the same file.
That can be done by hierarchizing your headers to prevent cyclic inclusions. This is the case in the Plan 9 libc. I do that too in my personal projects. It's piss easy to do, and it saves compile time.

Also by using incomplete struct declarations.
And C11 allows repeating typedefs of the same thing.

Just because you don't include it multiple times doesn't mean that others using it won't. As a general rule of thumb, every header MUST have an #ifndef guard.

So I'm going into my third year out of 4 for my comp sci degree. They've literally only taught me java (I know discrete math and data structures and shit though), and after this year I'll know C and Assembly and will have taken classes on Hardware and Operating Systems, maybe even Compilers or Databases. I really wanna get an internship next summer, but I was looking at a lot of them and it seems like that won't be enough, I'll need to learn more stuff on my own to get an actual, meaningful internship. I know a bit of C++, but aside from that, that's pretty much it. In a perfect world, I'd become a Games Developer, but I'm also interesting in Security and Application Development. What should I learn in my free time? SQL? PHP? CSS/HTML? Python? I have no idea desu.
>tl;dr: What languages and shit should I know to get an internship? I only really know Java at this point.

suicidal thoughts are normal right

>doing a lab in cpp class
>professor is an old fart who worked at bell labs for like 40 years
>get an error, raise hand, ask professor what I should do
>"eh that's just visual studio. It's just so terrible, honestly. I mean, if we were using Unix, there would be no problem at all! Microsoft are terrible at making products."
>makes me log off the lab computer and rewrite my code in another one because apparently that's the only way to fix it
>digresses about how great unix is every single lecture, I shit you not

how do you stress test a program or a web app?

Actually they aren't, but it is becoming increasingly more normal with each passing year. Why are you suicidal, user?

Why were you on Visual Studio to begin with if the lab required you to use a Unix machine?

Not sure what he's on about. Aside from the msvc optimizer the Cpp side of the compiler is ok. They're slow to get on the latest features though

>actually using botnet studio
kys faggot

shit taste
even moot likes asuka

I'm talking about Visual Studio Code, a free editor microsoft released for mac and linux.

It sounds ridiculous, like the time they release IE for linux, but it's pretty fucking awesome.

dunno
i feel like a fat piece of garbage who is constantly re-realizing what a fat piece of garbage he is, reconsidering solving the problem of his existence by ending it, giving up on the idea and forgetting until next time which tends to come five minutes later
it's like dory from finding nemo but if she was a lazy slob and hated herself
programming used to help ignore the thoughts but now they won't even let me program
doing anything to change or improve is of course out of the question because that would be a tremendous demand on my capacity for self reflection and motivation which seems to be woefully limited to kicking myself in the mental groin just to remember it hurts

He's right, you knowl

it didn't require us to use a unix machine
all the lab computers use windows 10 though

>not just using tmux, vim, make, and valgrind as your ide

vim
vi
virgin

>implying
wrong, I'm no virgin
my dad made sure of that when i was 6
receiving counts right?

Does anyone have any sources on strategies for synchronizing threads? For example, how rust uses and implements the Arc type? Info that's useful for posix threads would be nice but I'll take pretty much anything.