/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1549496358447.jpg (1280x720, 130K)

Other urls found in this thread:

port70.net/~nsz/c/c11/n1570.html#J.2
u.teknik.io/p75OP.pdf#oxJkP8759CGEb6MfsYg84TIehsD2emEJ
youtube.com/watch?v=uiJycy6dFSQ
twitter.com/SFWRedditImages

I appreciate the photoshopped books in this pics

Thank you for posting an anime image.
Although a Touhou one would have been better. :^(

Defining every UB in C

Attached: 1555390423905.jpg (393x474, 34K)

>What are you working on, Jow Forums?
A tool to verify if a C compiler is standard compliant and if it isn't, an alert is then sent to [email protected].

Good luck defining unterminated C strings lol.
Go ahead, try.

Attached: 1551587446176.png (600x600, 661K)

back to your containment board

port70.net/~nsz/c/c11/n1570.html#J.2

Attached: shitgetserious.png (2271x2380, 298K)

I don't think he'll read it.

C code doesn’t exist. Only UB.

here's an example of undefined behavior in C:

char myArray[4] = { 'a', 'b', 'c', 'd'}
char otherVar = 'e';

for (char *p = myArray, p < &otherVar , p++)
putchar(*p);


The comparision of a pointer within an array to a pointer outside that array is undefined behavior. That means that the compiler isn't restricted in how it may arrange this memory on the stack. otherVar may be located before or after the array in memory, and may even be non-adjacent, depending on how the optimizer and compiler feels like implementing shit. Compiling this code under different compilers may or may not work as intended, since the compiler writers have no obligation to interpret buggy/wrong code the same way between different implementations.

>The only time you _can_ blame them is if your code is standards-compliant, but still fails to compile, or does not work as expected.
See that's where UB is a problem up. It's NOT explicitly an error its "undefined". That means the compiler implementer is allowed to do whatever they want. Which includes silently deleting/rewriting/reordering code containing UB.

In earlier versions of GCC, optimization was far less rampant and people were able to write many programs which executed just fine when compiled as written. But as optimization improved their programs began to break because they hadn't considered the minutia of UB. And when problems in the language were found, they ended up being thrown into UB instead of being addressed correctly by the standard. This is why many industry C application still use C99 and some gcc version from a decade ago. They know it works, and it is too dangerous to upgrade their tools because its impossible to predict what might happen without a full code review.

Imagine breaking in and raping her

i want to nakadashi karen

>And when problems in the language were found, they ended up being thrown into UB instead of being addressed correctly by the standard.
Such as?

If the standards committee were to define every UB, the standard would literally be infinite characters long

How do you like my TypeScript?
var stripeCallbacks = {
processing: function () { animateToDiv(2, $('#processingDiv')) },
success: function (result) { paymentSuccess(result, $("#paymentDivContainerDiv").data("successurl")) },
failure: function (error) {
$("#databaseFailureSpan,#chargeFailureSpan,#unknownFailureSpan").hide();
if (error == "databaseError") {
$("#databaseFailureSpan").show();
} else if (error == "stripeError") {
$("#chargeFailureSpan").show();
} else {
$("#unknownFailureSpan").show();
}
animateToDiv(3, $('#failureDiv'));
},
};

It’s funny you mention that, because they had to recently rewrite some sections to make it possible to implement std threads in C11 as proposed.
There is no reason for the list to be that long when many of them items could simply be moved from UB to error.

Anyone know a good way to learn how to write a synthesizer in C++

I've tried looking. The thing about audio synthesis is that it's so simple on a basic level that all the tutorials just assume you have this basic level of knowledge and skip to a bunch of extraneous stuff

How do I make noise on a computer?
I'd prefer to write it on Linux

Attached: 56605138_179667916353136_3149400793144298782_n.jpg (1080x1080, 122K)

predicate valid_str0(const char *s) = \exists size_t n; s[n] == '\0' && \valid_read(s+(0..n));

LMAO

>Audio on linux
you're in for a fun time my friendo

>The character sequence in an #include preprocessing directive does not start with a letter (6.10.2).

CUTE

I want to switch the language from C++ to JS, since I have always been sort of dumb and unable to comprehend the tasks where C++ is used (graphics, computer vision, hardware, etc.). I'm getting the pay cheque but it makes me extremely miserable.

Look into pulse-code modulation and a library to open an audio device like aolib.

__--PulseAudio--__
good luck with that shit ahahaha

Attached: 1554952365507.jpg (497x497, 32K)

>to JS,
Sounds awful. I'm afraid of having to learn 100 frameworks

I love Satori.

Attached: satori.jpg (1200x1100, 375K)

u.teknik.io/p75OP.pdf#oxJkP8759CGEb6MfsYg84TIehsD2emEJ

Attached: umarusee.jpg (1280x720, 95K)

All commands are internally built. I'm writing the program in C# Winforms, and I did do it using parameters, not plaintext strings. Only one of the commands takes user input. But I have this problem on many commands, not just the one that takes user input. The rest of the commands are mostly just filters on dates. Like "All records made > 21 days ago", where 21 is hard-coded.

This is only the 2nd project I've worked on on my own, so I suspect I'm missing something that's common knowledge.

whoops posted in wrong thread UB are errors, but the compiler is not required to detect them
it would be infeasibly difficult, for example, to require that the compiler trace all possible execution paths and GUARANTEE that all possibilities lead to this pointer being initialized before you dereference it, especially if it's contained within some struct on the heap that you created in some totally separate part of the program
so dereferencing an uninitialized pointer is UB: it is "wrong", but the compiler is not required to check for it and produce an error/warning message at compile-time.

replying to

It doesn't matter what the device is, you use a library to abstract it. using aolib is piss easy.

I'm looking to go super low-level here

Not that I'm arguing with your suggestions. I'm going in kind of blind here

Like I want a basic way to interface with making sound on a computer, and literally everything else is written by me. If I were to use some kind of library, it would be akin to OpenGL

Who uses the "D" language and why?

>too dumb for C++
>can't handle node_modules and meme frameworks that span every milliseconds
C#

aolib, if you use ALSA or pulseaudio directly your won't run anywhere without those. aolib is just open an audio device, send audio data to it, close the device.

Are you just connecting to a database using the built in stuff? I strongly recommend using Dapper to handle that for you and it'll give you much better error messages.

Shitty answer "lol rewrite" but you will not regret it and it shouldn't take that long.

OpenAL

I do. It's criminally underrated.

It's C++, if C++ were designed from the beginning by people that understand the word "quality control" and just have basic intuition about what makes sense in a programming language.

There's a million little things that you notice and go "huh, I guess that makes sense" that all add up into something astronomically more well designed than C++.

Why are only Jow Forums and Jow Forums nice to me? Jow Forums, /x/, and /sci/ treat me like shit.

Attached: A8DF7DDE-FD0B-4782-8717-3880A7E69D15.jpg (403x433, 25K)

Andrei and nobody else
>r9k
Fuck off back there retard

Attached: 1553756620115.png (392x462, 174K)

Yes, I'm just using the built in stuff, because I couldn't figure out how to set up Entity.

get out loser

Attached: 1544378417379.jpg (369x273, 13K)

I've done some toy projects in D but never anything serious. I have heard that Facebook use D internally.

The problem is not the language, but in the tasks which require the knowledge of C++. Computer vision, embedded programming, OS'es, high-performant applications, algorithms. I have gotten the job pretty easily but I regret I didn't pursue JS or other mindless CRUD shit.

Fuck EF it's a piece of shit, dapper is 1 nuget package and will do exactly what your current OleDb things do in fewer lines and with better messages.

So how many execution paths need to be traced to verify a string literal is closed? Why is that UB?

This.EF is slow and targeted for enterprise™ codebases that want shitty ms support

C is UB.

Yeah now good luck implementing that in a performant manner.

you're welcome

t. made that image years ago

Attached: 1492893712908.jpg (600x571, 86K)

EF isn't slow it's just very easy to not know what the fuck you're doing and treat the most performant software you'll ever use like a dumb data store.

I'll never recommend it but for what it sets out to do it does it very well.

"String literals" are compile-time syntax and it is trivially easy to detect an unclosed one.
I assume what you meant to talk about was strings being null-terminated.

C has little or no language-level array support, and arrays are simply passed as pointers to the first element.
Knowing the length of an array requires the programmer to keep track somehow.
In many cases, this is accomplished by passing a "length" parameter alongside the pointer-to-first element.
In the case of c strings, it is accomplished by putting a sentinel value (the null character) at the end of the array.
Strings are simply an additional set of constraints placed on arrays of chars, so it is possible to pass a string to a function that wants an explicit length argument rather than a null terminator.
Passing the wrong length to such function (i.e., programmer error) may lead to overwriting the end of the array and clobbering the null terminator that was supposed to exist there.
Now, if this "corrupted" char pointer is passed to a string function, the function will be unable to find the null character at the end of the array (since it doesn't exist) and so will continue past the edge of contiguous memory into something else's space, until eventually it DOES find a 0 byte.

A string function cannot "know" whether the null is properly at the end of the array or whether it has overflown because it uses the null to FIND the end of the array.
The compiler does not know the "length" of an array passed as pointer, so it has no way to know that you are overflowing past the legal space in a string and overwriting the null terminator.
Furthermore, the compiler does not psychically know which arrays of characters are really just arrays or buffers and which ones the programmer will later wish to treat as a C string, so even if it did know the size of the array it would not be able to know whether it was "legal" to overwrite a '\0' in the last element.

it has the overhead of a garbage collector, so i would never use it for the things one would use C++ for
perhaps it would be better to compare it to C# and Java, since those seem like more direct competitors

PortAudio
I did a project like yours and it fits the bill. You don't have to worry about the backend, just what you feed to the channels. So basically you can load audio from a file or write your own function to generate them. Is easy to play around with too. Only problem is that the documentation is shit, but with enough experiment it won't stay a probelm.

I think garbage collection is just about the only high-level thing that might be kind of subjective and perhaps not a direct competitor

In just about every other way it's just a cleaner version of C++ though

Then again, the optimizations in C++ are so advanced and so convoluted that it's not exactly like you have direct control if you're using anything in the standard library.
I've routinely heard Jason Turner say that he can't make sense of hiccups in performance. And when Jason Turner is confused about what's happening in C++ I think it's more than a little convoluted.

No I am talking about string literals it’s UB 6.4.
>An unmatched ' or " character is encountered on a logical source line during tokenization (6.4)
How can you talk so confidently about UB without knowing it inside and out?

You can't efficiently detect pointers to garbage user

counting how many words there are in list, that starts with certain letter, in Scala
object MiniDictionaryApp {
def main(args: Array[String]): Unit = {
val myDict = List("apple",
"cow",
"color",
"god",
"goat",
"dog",
"house",
"mother",
"orange",
"rat",
"zeal",
"real",
"rat",
"university",
"honorificabilitudinitatibus",
"floccinaucinihilipilification",
"pseudopseudohypoparathyroidism",
"supercalifragilisticexpialidocious",
"pneumonoultramicroscopicsilicovolcanoconiosis")

val tuple = myDict.map(x=> (x.charAt(0), x))
val list2 = tuple.groupBy(_._1).mapValue(_.map(_._2)).toList
list2.foreach(x=> println(x._1 + ": " + x._2.size))
}
}

Attached: scala waifu.png (258x376, 89K)

How does D compare with Rust?

I feel like I'm hearing a lot more about Rust lately..

I am so fucking thankful I spent hours reading the dragon book and compiler tutorials. It is so nice being able to write your own systems language without compiler version bullshit and general C bullshit. Not bragging, just presenting a solution to a lot of the complaints here.

rust fast

You can safely ignore Rust. Everything good that can be said about it is also true of D, and there are lots of problems Rust has that D doesn't. The Rust hype is totally undeserved.

>don't like visual studio? Just invent your own computer, pleb

D is a literal deadlang.
Rust is a language on its way to becoming a deadlang, and is only talked about positively by people who don't actually program.

oh okay that's just stupid
there's no reason it shouldn't be a compiler error

pls use F# instead. Scala was a mistake.

Redpill me on Ruby.
I have never used it and I have one day to make a simple SQL app.

This but unironically.

Show us your language, then. Also make sure the codegen isn't shit.

I don't know why "other people aren't using it" is supposed to be a rebuttal

Besides there not being a lot of libraries

I'm still completely fucking lost as to what this means (pic taken from my local Community College site), but I still don't even know *what a Liberal Arts major is* either.
Google isn't helping, people I've asked aren't helping, I've even asked the adviser at the college
>Good morning. The degree plan you are referring to is an Associate of Arts degree under the Liberal Arts program with an emphasis on Computer Science. This is the route students choose for transfer to a 4-year college or university, as opposed to an Associate of Applied Science degree, which is a two-year program not designed for transfer. Please let me know if I can assist you further. Thank you for your inquiry, and have a great day!
What the fuck is this?
Can I get a Bachelors in Computer Science with whatever this shit is or not?
Also what is he talking about? I thought you could transfer with an Associates of Sciences degree?
Am I just overthinking this shit?

Attached: what.png (775x272, 19K)

>C has little or no language-level array support, and arrays are simply passed as pointers to the first element.
>Knowing the length of an array requires the programmer to keep track somehow.
How does it know what order to put those groups in?

scala is both functional, and there are jerbs in it, sounds fine for me

you want applied science, not liberal arts

There's jobs in f# too.

Scala is a mad house that will eventually make you want to kill yourself:
youtube.com/watch?v=uiJycy6dFSQ

Scala is functional like C++ is OO

So is the adviser just wrong then? He said an Associates of Applied Science is not designed for transfer, which is what I want to do - get an Associates in Computer Science at a community college, then transfer and get the Bachelors.
Why the fuck is this shit such a mess?

not all of them are transferable, yes. aas is still better tho cause it's not as bloated with bullshit courses you'll never utilize

Depends on what courses the university will transfer from college. I would listen to the advisors at both institutions and take the classes they tell you.
I did a diploma in electrical technology at a respected college and none of it was eligible for transfer at university because the course material did not line up between the schools.

Make a smaller factorial function in C. I'll wait.
f(n){return n?n*f(n-1):1;}

NODHING :DDDDDDDDDD

hahahahah, HAHAHAHAHA!

ABSOLUTELY NOTHING.

Attached: nothing of value.png (429x96, 15K)

That's what I thought - AAS/AS is narrower, more focused on the shit you want to do, and AA is wider with less of a focus on what you want to do.
Sadly I can't find a Community College as close to me as this one, so I either have to settle with this or just not go at all until later down the line when/if I move...
I've grown up on Jow Forums so I have heard all about how "Liberal Arts degrees are useless", so seeing "Liberal Arts" anywhere on that page in the pic I posted strikes the fear of god into me.
What in the fuck does this even mean?
>Completion of an Associate of Arts Liberal Arts Degree with an emphasis in Computer Science
Fucking Christ.

How hard is it to get a job related to programming in burgerland without a degree?

Attached: 8a6c3bbba8865aaedddd29e5545f5776fd62a67375181184e04e7ada610b8e3c.png (1564x1415, 1.15M)

>C
>function definition doesn't specify return or argument type

i thought everyone was going to those meme webdev coding bootcamps
probably pretty easy to get job if you have portfolio to point at and do well in coding interview

That's valid in C89 only, where things missing its type default to int.

async/await is a fucking terrible abstraction for concurrency. is syntactic sugar to make your code "easier to read" really worth making it 1000x harder to debug/reason about?

what the fuck was wrong with Futures/Promises?

Attached: 1 2Nco5zYP_Xv-5-FgL6kCuw.png (1280x400, 19K)

That's permitted in K&R C. Return type will default to int when unspecified, and parameters will default to int when unspecified.

Will evoke a warning on modern compilers, though.

>recursive
void f(n) {for(int i=n; i;n*(i--) ;
}

What's wrong with async/await? it's just syntactic sugar around promises.

They are. Poster is just retarded.

>async/await is a fucking terrible abstraction for concurrency.
Why?

>is syntactic sugar to make your code "easier to read" really worth making it 1000x harder to debug/reason about?
No, but I don't see how that would apply to async/await. Can you elaborate?

>what the fuck was wrong with Futures/Promises?
Depending on the situation, code using it is harder to read than coroutine code.

It’s UB.

forgot the * and x=

>making it 1000x harder to debug/reason about?
I don't see how it does that. Maybe you just don't have a very good grasp of async/await

honestly, just go for the aas from a school that offers a bas and say you were studying for the bas the whole time. not all places require a bas to work at, even if it's in the job requirements, and not all of them will verify or even ask you about it. (unless you get fucked and get interviewed by someone that either went/knows someone that went to the school)