/tech/ - Technology

Technology & Computing


⊖ Thread has reached reply limit.


college-grade_programming.png
[Hide] (133.3KB, 3000x3000)
It's like /agdg/ except without videogames. Well there wasn't any videogames to begin with, but now there may be other software.

See also /agdg/ at >>>/v/ for videogames.

What are you working on?
Replies: >>1412 >>2510
There isn't really a screenshot for it, but I just finished improving my mouse input system.

The program now only handles mouse events in 2 cases: either the mouse is doing something on top of the window, or you click-and-dragged outside of the window. It was more annoying to do than it sounds because Windows only fires input events when the mouse is over the window, so you can't drag out from it (which makes sliders and such annoying if they're near the window edge). But if you get global mouse position manually, it doesn't have any information about whether some other window is obscuring yours. Global mouse position is also based on the monitor, not based on the window unlike the mouse move events, so you have to fix that. You also need to detect when you lift a button while the mouse is away from the window (which again Windows doesn't fire an event for), otherwise you get the age old issue where the button gets stuck on until you click on the window again.

I need this because next I'm going to work on a program that has custom controls for moving/scaling the window, and it needs to mostly sit idle so I don't want any unnecessary mouse events causing it to run logic and use CPU.
Replies: >>1418
>>1410 (OP) 
>fixing up emulators & controller tools to not be shit
mostly minor changes but these minor changes were really starting to annoy me
winder.webm
[Hide] (946.9KB, 620x434, 00:19)
>>1411
Got the window UI figured out, now I just need to actually put something in it. This is a remake of an older program, an image viewer of sorts.
Replies: >>1419 >>1456 >>1494
>>1418
what's this? an imgui clone? I haven't seen the previous thread
Replies: >>1424
PSA on toilets:
https://invidious.tube/watch?v=8SUkrR7ZfTA
>>1419
>an imgui clone?
I'm not sure what you mean by that, imgui is an idea about how to manage a GUI. If you mean Dear Imgui then no, I wouldn't call what I'm doing a UI system at all, I needed a bunch of buttons so I just made an array of buttons. The UI is just means to an end rather than a project in itself.
>>1418
Very cool Anon.
Working through the graphics chapters in Stroustrup's PPP2, and working on creating a wrapper library for FLTK that eliminates the need to write C code to use it. The author of the library claims it's 'C++' but plainly it's 'C with classes' at best. Hardly surprising given it's heritage goes all the way back to SGI & the NeXT.

Anyway, when I'm done we should have a very simple to use, very portable, very high performance GUI/windowing system that will run smoothly on even tiny microcontrollers if needed. 

This is an interesting area to learn and touches on a lot of different disciplines, as Bjarne correctly points out. It will be a good learning exercise for me, and will teach me a lot about doing efficient library design using C++.
Replies: >>1461
>>1457
why a wrapper though? wouldn't it be easier to just fork FLTK 1.x and replace raw pointers with RAII pointers, const char* with string_view, char* with string, and function pointers with std::function<...>?
Replies: >>1462
>>1461
>wouldn't it be easier
No, heh it definitely wouldn't be easier. FLTK is a big-ass library (unsurprising given it's basically a full-featured Windowing/GUI system over 30 years in development). So, I guess my reasons are mainly these two.
A) I'd like to have this done before Summer's end, not five years from now.
B) I'd like anons to simply install the FLTK dependency from their own repos, then my code will simply rely on that. 
Taken together, I think the wrapper idea is cleaner & less error prone. Besides, I've already succeeded at this approach for the cURL library, and it works fine that way.

But you're right about using modern C++ programming idioms Anon, they really are a good idea in general.
Replies: >>1463
>>1462
What is the difference between using modern C++ features and free()ing memory on my own?
I understand it seems like automatic but what's wrong with explicit memory management and C idioms?
Replies: >>1464
>>1463
>What is the difference between using modern C++ features and free()ing memory on my own?
Well, the first and most obvious one is, well, you Anon.
>and free()ing memory on my own
>my

Relying on humans to correctly and consistently manage resources properly has obviously been an utter failure. The computer does some things much better than we can, and RAII is one extremely good example of that.
Replies: >>1465 >>1466 >>1493
>>1464
And btw, RAII isn't 'modern' in that sense. It's been a part of C++ from the very, very beginning. Certainly by ARM in '85.
Replies: >>1466
>>1464
>>1465
Right, RAII isn't modern. And I know it's similar to auto-closing fridge doors. Then again, shouldn't people close their fridge doors on habit? It's just lazy or stupid not to anyways.
Replies: >>1468 >>1470
>>1466
Well it's not quite that simple Anon. Computing systems are prone to exceptional conditions. And men (there are no women in programming, really) aren't all that clever at the foresight required to anticipate all those possibilities.

Even if you free resources dutifully in the recommend fashion, exceptional states can often render those steps useless. RAII basically always does the right thing, and it relies on very little else to do so. Certainly not the men involved, for instance.
Replies: >>1472
>>1466
not him, but:
first, have in mind that C++ RAII unique_ptr implementation doesn't have memory overhead unless you use a custom destructor (which you almost never do), and won't affect execution time as long as you use -O1/2/3 (which remove the additional function call on creation).

there are many inconveniences with manual memory de-allocation; just to name a few that come to my mind:
0. let X be an array of structs Y with arrays Z inside. do I really want to write de-allocation functions for all those types? it's going to be exactly the same for all of them.
1. suppose I have a function and I want to insert "early returns" (a common pattern when using error codes); without RAII, I would have to free all my resources before every return statement.
2. I can't make "ownership" explicit with raw pointers syntax, so I'm going to have to document which pointers I'm supposed to free (FLTK does this).
3. many algorithms require ref-count'd pointers. C++ ref-count implementation has been the same for decades

so here are the two main reasons why I use RAII:
>have to write less code for exactly the same functionality
>0 (zero) overhead

just give it a try anon, it stops feeling wrong after the first three or four times. besides, if you are on GNU, you can use gcc -S -O2 <your file> and check the generated x86 by yourself.
Replies: >>1472
>>1468
I see. By using those features, the foresight can be shared and inherited. It makes sense to use them if and only if the programmer knows what they are doing. Blindly following practices just like a pajeet is bad, especially when the execution is not explicit.
>>1470
I will. Still prefer C with class for now, will try adding in RAII to the mix.
1616402034220.png
[Hide] (200.6KB, 421x519)
I should just nuke this thread from orbit before another anon contracts this pajeet aids.
Replies: >>1475
>>1474
What aids?
>>1464
i don't care if the pajeets can do it or if it melts their brain all the more reason to call them retards.
memory management is so easy it doesn't even factor to the difficulty of writing a program usually.

and you are not supposed to use malloc and free regularly inside functions for like whatever.
its methods you should rarely use, insted of using raii learn to use your brain.

all these problems and more can be solved if you just learned assembly
Replies: >>1497 >>1508
image.webm
[Hide] (3.1MB, 648x464, 00:29)
>>1418
>it's fine if I procrastinate and play videogames a bit
>suddenly it's 4 days later
Where does time go

Continuing this, you can now actually view images on it. I don't have a smooth image scaling function yet though, so the image looks a bit messy when zoomed out.
Replies: >>1495
scaling.webm
[Hide] (2.1MB, 598x452, 00:25)
>>1494
Continuing with some UX. The image gets centered to the window when you open it, and also scaled down if it's too big to fit the window. The bottom left button now also works, it toggles between fitting the image into the window, and filling the window with the image.
Replies: >>1510
long_bs.png
[Hide] (330KB, 834x344)
>>1493
>factor to the difficulty of writing a program usually
>use malloc and free regularly inside functions for like whatever
nobody said that. why can't you refute a simple point and have to embarrass yourself?

not him but, assembly isn't hard, it's probably the most simple and easy to learn programming language. most comp-sci students learn x86_64 and mips64 in their first year.

the only good reason to mention asm (x86 in particular) would be to point out the overhead of an additional PLT symbol lookup (1 jmp, ~2 movs, 1 ret) the first time an object is deleted, but only IF the call destination address was not resolved at link time (unlikely).
>>1493
>all these problems and more can be solved if you just learned assembly
But I did learn assembly Anon. I even did it before C and then C++. C++ brings so many benefits to the table, with so little overhead related (usually no overhead) that to me it's an absolute no-brainer to use the language for any resource-constrained projects as long as a build system is supported on the platform. Since today that includes practically every platform it's an easy choice IMO. Some things are better to do in Bash or even Python. But for practically everything else C++ produces the singular best results -- both for size, runtime perf, extensibility & maintainability.

Perhaps in the future some like Golang (if you can stomach the poz of the community itself) may displace C++ for systems programming, perhaps not. Regardless, neither Assembler nor C ever stand a chance of doing so.
Replies: >>1511 >>1553 >>1572
pasta.webm
[Hide] (4.2MB, 1292x788, 00:41)
>>1495
Added more ways to open images. You can now drag images in from a web browser, copy&paste bitmaps from a browser or image editor, and also copy transparent images from Krita and Gimp. Anything that puts a regular bitmap into the clipboard should work, and I think programs like Krita always do that as fallback. I don't know if there's a commonly accepted clipboard format for images with transparency, Gimp and Krita both put a png file into the clipboard, but they use a different ID and name ("image/png" from Krita and "PNG" from Gimp). Not sure what other programs like Photoshop do.

Strangely you can't copypaste stuff from Krita into Gimp. You can copy from MS Paint into Gimp so Gimp does recognize the default bitmap. Both I and MS Paint can successfully read the bitmap data from all 3 programs, so I wonder why Gimp can't read it when it comes from Krita.
Replies: >>1514 >>1547
>>1508
>neither Assembler nor C ever stand a chance of doing so.
>C
C is already the de-facto systems programming language.
Replies: >>1553
scale.webm
[Hide] (2MB, 450x324, 00:21)
>>1510
Smooth scaling now works. It scales in a separate thread when the zoom level changes, in the meantime a quick preview is shown.

This is the first time I'm using threading for any actual purpose, and I already hate it. I can only imagine what a mess it would be to add threading to a videogame and managing a million mutexes for everything. I wish you could use a bracket scope syntax for them, so instead of this:
lock_mutex(cia_killer_mutex);
	// process CIA niggers
unlock_mutex(cia_killer_mutex);You could just do something like this:
cia_killer_mutex {
	// process CIA niggers
}
Replies: >>1515 >>1531
>>1514
I found this book on multi-threaded shared-memory programming to be quite interesting. You can check it out: https://cdn.kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook.html
Replies: >>1516
>>1515
>881 pages
I have better things to do with my time but thanks, I'll save it just in case.
Replies: >>1517
>>1516
>I have better things to do with my time
really, like what
Replies: >>1518
>>1517
Programming. Reading that much for what will probably amount to a handful of neat tricks isn't worth stopping programming for. How much would I learn that I wouldn't learn by doing multithreaded programming for the same amount of time anyway? Rhetorical question.
Replies: >>1520 >>1523
>>1518
Skim and skip. You can probably learn quite a bit of tricks that are not easily searchable.
Replies: >>1524
>>1518
>I can't learn to program properly I have to shit on the street
Pajeet, you should be as far away from computers as possible.
Replies: >>1524
>>1520
Sounds like needle in a haystack. I mean I'm sure there's useful stuff there, but nothing I'm going to do for a long time warrants a >500 page book.

>>1523
How about you post your program instead of whining about what other people do.
scaling.webm
[Hide] (3.9MB, 982x682, 00:41)
>>1514
Holding Shift now preserves window aspect ratio, and holding Ctrl will scale the image along with the window. Clicking and dragging with right/middle mouse will scale the image linearly.
The point under mouse will now stay in place when zooming.
The bottom right button now works, it scales the window to the image size.
Nigger rigged my old bitmap text system to show zoom level, and instructions at startup. The instructions text isn't perfectly centered because it includes spaces in the row width, but I'll probably write a whole new bitmap font system sometime.
UI is now visible when dragging stuff even if mouse leaves the window.
Sprites are embedded into the file so the executable is completely standalone. There is a file though, which you can edit to customize the icons, but if the file isn't found then the embedded data is used as fallback.

I think this program is now complete as long as I'm not forgetting anything. Well, I still need to figure out how prevent stb_image_resize from fucking up the alpha channel when it does a smooth rescale.
Replies: >>1535
flip.webm
[Hide] (2.4MB, 514x376, 00:24)
>>1531
There was something I was supposed to add after all: buttons to flip the image.

>prevent stb_image_resize from fucking up the alpha channel
Never mind I'm retarded, I wasn't enabling the alpha channel on the scaled down image, so my own drawing function was ignoring alpha. I didn't realize because it's usually enabled automatically when I load an image file.

Anyway it's done, here it is in case anyone is curious:
https://tsun.itch.io/reference-image-window
It is meant to be a tool that artists can use to view a reference image while they draw.
>>1510
Nice work lad.
>>1535
I looked around but I couldn't find the source code Anon?
paint.webm
[Hide] (106.8KB, 600x400, 00:07)
Photoshop watch out.

The reason I worked on >>1535 is because I thought it would be a good warmup to what I really want to work on: a graphics editor. I've been working on the UI and design of this program for ages for fun, I'm very happy with how it all looks so now I just have to worry about actually making it.
Replies: >>1553 >>2862
>>1508
> Some things are better to do in Bash
No, shell sucks ass, unless it is absolutely 100% trivial.

> with so little overhead related (usually no overhead) 
OOP adds a memory overhead. And C++'s convenient features (good example is vectors which are actually truly convenient) do things behind your back (by design) which is an issue when programming systems software or embedded systems.

> Golang (if you can stomach the poz of the community itself) may displace C++ for systems programming,
Golang will never displace or replace C nor C++. Golang is not good for systems programming. Golang is good for creating tools and, in general, Go is a less harmful python replacement.

> C++ produces the singular best results for maintainability
Not unless you and your team follows a strict style guide that tells which features you can use. C++ has a ton of features and C++ is way more complex language than C.

>>1511
> C is already the de-facto systems programming language.
Either C or "C-style" C++ (without OOP or anything that uses OOP or anything that has a big overhead in general) C-style C++ can be better than C because the C++ compiler does more checks and you get some extra features. 

>>1535
>>1549
Good Job Anon!
Replies: >>1554 >>1555 >>1564
>>1553
>shell sucks ass
Do you mean POSIX shell sucks or the concept of shell sucks? Why?
Replies: >>1556 >>1557
>>1553
C++ can help create much more maintainable code than C ever can. And as with much of the rest of your postions in this post, you have the point about strict guidelines exactly backwards: the only way you can ever hope to have maintainable large C projects is by them. Well-written C++ naturally tends to enforce the designer's intentions well, by design. It's much much easier to creating a steaming pile with a good C developer's code than with a good C++ developer's.

>C-style C++ can be better than C because the C++ compiler does more checks and you get some extra features. 
It's true that C++ compilers are better than C ones, but 'C-style C++' is neither, and sort of an abomination. C developers may like that shit, but certainly no professional C++ developers do.
Replies: >>1557 >>1568 >>1572
>>1554
I'm not him, but both suck and I'm angry. Angry about shell.

POSIX shell is completely useless for any serious programming, see http://www.etalabs.net/sh_tricks.html for a good rundown on some of the myriad ways it sucks. The other extension shells aren't much better, sh is just the most outrageous of them all. Writing a shell program that handles all inputs correctly is straight up impossible because there is so much hidden and retarded "helpful" action that you can't possibly keep all of it in your head.

Almost everything has to be prefixed by some gargantuan BE_RETARDED=NO --dont-do-the-retarded-thing --no-really-stop-being-retarded song and dance, with no way to get rid of it once and for all. I doubt you knew all of the pitfalls in that link, and before you misunderstand this as a challenge to try and learn them so you can be 1337 Unix Greybeard, let me say that memorizing that shit is a colossal waste of your time and runs counter to the point of a computer, which is to automate work, not create it. The reason you see all these shitty to mediocre "scripting languages" pop up again and again is that the shell sucks.


The concept of a shell as found in Unix sucks because what you get is a really retarded programming environment where everything has to be built from global variables (called files), byte streams and fuckhuge variadic functions (called programs) that take opaque byte arrays (called arguments) and return a small integer (called return code). Anything beyond that must be reimplemented by every single program and thus ends up wildly inconsistent.

What you're doing in the shell is really programming - the environment and language are just so thoroughly crippled and useless that you don't even recognize it as programming half of the time. The classic example of a system that does this right is Genera, but really any proper programming environment would be an improvement, even if it's just the javashit REPL of your browser. When you hear windowsfags rave about Powershell, that's because it fixes some of these issues. I don't know how many of them though, wild horses couldn't drag me to Microsoft land anymore.
Replies: >>1557
>>1554
> Do you mean POSIX shell sucks
Yes and so do all POSIX shell look-a-likes.

>>1555
> you have the point about strict guidelines exactly backwards
Let me reiterate: because C++ has so many features and so much more complexity in the language, you simply cannot use all of the features. If you are working with a team, you should pick the allowed features to prevent your codebase from becoming a mess.

>no professional C++ developers do.
Like I said, C++ is not suitable for embedded systems or resource (especially memory) constrained environments/software (Unless, you use "C-style" C++)

>by design. It's much much easier to creating a steaming pile with a good C developer's code than with a good C++ developer's.
Define what you mean by "steaming pile" exactly. are you complaining about Cstrings again? (I never claimed that C has good support for strings) or are you complaining about the C type system (which I never praised). Don't tell me you are actually comparing a legacy codebase (that can date back decades) to a modern one. Finally, if you are complaining about muh header files, then you must realize that modules were introduced to C++ just recently.

>>1556
> I don't know how many of them though, wild horses couldn't drag me to Microsoft land anymore.
FYI, PowersHell also works on GNU/Linux: https://github.com/PowerShell/PowerShell (but I have never used it on Linux)
Replies: >>2140
>>1553
>OOP adds a memory overhead
OOP != C++. you can do OOP with C. actually, most big C projects do, in an inconsistent and inefficient way (see the linux kernel or any other C project with more than 20K LOC).

>vectors which are actually truly convenient
[citation needed]

>do things behind your back (by design)
[citation needed]

>which is an issue when programming systems software or embedded systems
if you don't know the difference between stack and heap you shouldn't be near embedded systems anyway. literally not a language problem.

>Not unless you and your team follows a strict style guide that tells which features you can use.
guidelines are just common sense, they only exists because companies keep hiring uneducated retards to drive wages down.

>C-style C++
>what is const
>what is constexpr
definitely not C

have you ever programmed an embedded device? people don't use C because they want, most of the time they do because there are no C++ (or any other language) compilers for those ISAs, and companies are too greedy to spend money developing a C++ compiler just for constexpr and consteval.

internet 1337 h4x0rs praising handwritten vtables are mentally ill
Replies: >>1572 >>1594
>>1555
>It's true that C++ compilers are better than C ones, but 'C-style C++' is neither, and sort of an abomination. C developers may like that shit, but certainly no professional C++ developers do.
Mike Acton, former Engine Director from Insomniac Games, and current Principal Engineer at Unity, in charge of the complete overhaul they're doing of their backend to try and make their performance not dogshit. Well known advocate of Data Oriented Programming, one paraphrased quote from him is "we only hire C++ programmers because they're easy to find, then teach them to write C in C++ instead"
Replies: >>1569 >>1593
.jpg
[Hide] (24.2KB, 600x400)
>>1568
Kill this anon, he is refusing to accept C++ into his heart and soul. This is unacceptable. Not using [latest C++ features] and believing in the C++ committee is the highest form of sin. C++ is perfection, C++ is god. Programming anything without using at least 7 C++ features in it is bad coding practice.
>>1508
>>1555
honestly, we can agree to disagree if you don't want to discuss this any further since this kind of discussion is not very productive.

>>1564
> OOP != C++.
true, but OOP is one of the biggest features of C++.

>vectors which are actually truly convenient
>[citation needed]
>do things behind your back (by design)
>[citation needed]
the reason why vectors are convenient is that they do the allocation/growing behind your back. vectors use more memory than C arrays because vectors allocate more memory than what is actually needed.

> literally not a language problem.
yes it is. if you use those language features or stdlib functions/types you have less precise control over how the memory is being used. memory is usually the most precious resource in embedded systems and adding more memory is going to increase the cost (per unit) of the final product.
Replies: >>1584
forcefield.gif
[Hide] (985.9KB, 320x240)
I want to make a jigsaw puzzle engine for browsers, what's the best graphical interface to use for this? Was looking into WebGL but would like a second/third/nth opinion.
Replies: >>1576
>>1574
You literally have no options besides just drawing shit on a canvas directly, which is just going to be slower.
Replies: >>1583
>>1576
this, unless you want to port sdl2 to javascript, on top of webgl obviously
>>1572
>the reason why vectors are convenient is that they do the allocation/growing behind your back
doing something that you explicitly asked != doing something behind your back. all the documentation is pretty straight forward about memory allocation (which is mostly common sense, you shouldn't need documentation to know how std::vector works)

>vectors use more memory than C arrays
because they're different data structs that serve completely different purposes. if you don't need dynamic allocation, you should use std::array which is equivalent to C arrays but with more compile-time information and without the pitfalls (degradation, etc).

>if you use those language features
not a language feature. constexpr is a language feature

>stdlib functions/types you have less precise control over how the memory is being used
then don't use them? do you really need someone to explain that to you? that you have to choose the right tools and not be a complete retard?

namespace and std, not malloc and free ok. praise bjarne
Replies: >>1592
>>1584
>praise bjarne
Keke. There's a recent video interview done with him. This lockdown kikery is obviously really wearing on him over the past year. I'm a bit concerned over his health now tbh.
https://www.youtube.com/watch?v=8aIqIBmNJyM

BTW, you really seem to know what you're doing around the computer. Have you ever taught programming Anon? I have a thread intended to help complete newcomers get up to speed with C++ on our board, but so far no one's participated in it. I'm wondering if you have any tips on how to go about it properly?
>>1568
I'm quite aware of Mike's positions, and saw his presentation as the closing keynote for CppCon14. Mike's kind of a pandering ass, and laughably his only real agenda that day was to spew out verbal clickbait over his disgust with the audience he was being paid to serve. Maybe warranted, maybe not. But disingenuous of him at best.

But he is exactly right about keeping the cache line occupied as a performance key. The C++ Committee -- indeed all the systems programming world -- was quite aware of how the prefetcher works long before Acton took the stage that day.
do_not_want_wait_i_want.webm
[Hide] (1.3MB, 744x408, 00:10)
>>1564
>actually, most big C projects do, in an inconsistent and inefficient way (see the linux kernel or any other C project with more than 20K LOC).
This. Double-nigger this. If it weren't for the fact we have to actually wade through these steaming piles of ad-hoc chicanery on a regular basis, these DO  NOT WANT, DO NOT WANT, DO NOT WANT. oh wait...i want 
>
manchildren rants would be pretty laughable.

NIHS is basically a form of mental illness. One the rabid C crowd suffers from deplorably.
babbys_engine.jpg
[Hide] (75.4KB, 500x500)
>learn assembly
>it's just more verbose and specific C without a standard library
I thought it was supposed to be super hard and impossible to make programs with. Now I want to make a programming language that's just macros for assembly code and some syntax features.
Replies: >>1602 >>1608 >>1621
>>1596
Check out HLA or LLVM.
Replies: >>1604 >>1605 >>1608
>>1602
>HLA
/throd.
HLA.png
[Hide] (119.1KB, 1012x1024)
>>1602
Very interesting but I don't know what it has to do with programming.
Replies: >>1608
>>1596
>>1602
>>1605
HLA as in High Level Assembly (check out The Art of Assembly Language, 2nd edition by Randall Hyde) If you don't like HLA, check out the 1st edition of The Art of Assembly Language instead.
I dont know shit about computers let alone languages that make things happen, but can anyone help me understand the whole ordeal behind people exploiting terry davis image/work on cuckchan and holy c itself?

What made holy c different from the other c stuff and languages/engines you guys use?


I honestly just want to understand how fucked in the head you have to be to exploit a dead person to sell ugly clothing merchandise and the retards buying them
Replies: >>1611 >>1612
>>1610
The fuck are you talking about? How are people "exploiting" terry? What's going on?
Replies: >>1612
7bcd98a9d4d203f6f70961357368d4ffc5225506a590ab7e100b342986937ecc.png
[Hide] (676.4KB, 640x651)
DO_IT_LIKE_A_WHITE_MAN.mp4
[Hide] (409.3KB, 640x368, 00:09)
tad.webm
[Hide] (2.4MB, 429x592, 00:25)
182ecbcca3888478904e4b0a5194aec16aa1cfba16d3fd089c94974c3e3ee777.webm
[Hide] (4.9MB, 200x150, 02:00)
>>1610
> https://archive.org/download/TerryADavis_TempleOS_Archive/videos/
> https://archive.org/download/TempleOS_ISO_Archive
> https://web.archive.org/web/20170221041504/http://www.templeos.org/
> https://web.archive.org/web/20170304224627/http://www.templeos.org/Wb/Doc/HelpIndex.html
> https://web.archive.org/web/20170204193807/http://www.templeos.org/Wb/Doc/Welcome.html (important)
> https://web.archive.org/web/20161129044519/http://www.templeos.org:80/Wb/Doc/FAQ.html
> https://web.archive.org/web/20170204193809/http://www.templeos.org/Wb/Doc/Charter.html (important)

TempleOS's Features
possible language: html, relevance: 8
* Oracle in with <F7> for words or <SHIFT-F7> for passages.  See tongues.
* x86_64, ring-0-only, single-address-map (identity), multitasking kernel with multicore support.
* Master/Slave MultiCore 
* Free, public domain, 100% open source.
* 64-bit compiler/assembler for HolyC.  Truly compiles, doesn't interpret.  Just-in-Time and Ahead-of-Time compilation.  With JIT, no need for object or exe files.
* No 32-bit krufty code.
* 640x480 16 color VGA graphics.
* Keyboard & Mouse support.
* ATA PIO Hard drives, support for FAT32 and RedSea file systems with file compression.
* ATAPI PIO CD/DVD support with ISO9660 file system.  Can make bootable ISO9660  ISO files so you can roll-your-own distro's.
* Partitioning tool, installer, boot loaders for CD/DVD and hard disk.
* Editor/Browser for a new Document Format.  Source files and the command line window can have graphics, links, icons, trees, colors, super/sub scripts, margins. Everything is seamless through-out the tool chain.  No need for separate resource files.
* 8-bit ASCII, not just 7-bit.  Supported in entire tool chain.  <CTRL-ALT-a>
* Graphics in source code, no resource files, graphic sprite editor. <CTRL-r>
* 64-bit pointers.  All memory, even more than 4Gig, can be directly accessed by all tasks on all cores at all times.
* Ring-0-only.  Highest CPU privileged mode at all times.  No off-limits insts.  No time lost changing modes or address maps.  Switches tasks in half a microsecond.
* 2D/3D graphics library
* Real-time fancy differential-equation solver for physics engines, to use in games.  (Adaptive step-size Runge-Kutta, interpolated for real-time.)
* Auto-completion, jump-to-source tool called AutoComplete with Dictionary.
* Window Manager.  Pan scrn with <CTRL-LeftDrag>.  Zoom scrn on mouse cursor with <CTRL-ALT-z>/<CTRL-ALT-SHIFT-Z>.
* File Manager, <CTRL-d>.
* Code profiler, merge, diff utils.
* PC Speaker support with many hymns.
* Music composing tool.
* Many games, demos and documentation.
* All source code included.  Only compiles with the included TempleOS compiler and assembler.
> I dont know shit about computers
Read K&R, Learn HolyC. Install TempleOS. Entertain Mr. God.

> What made holy c different from the other c stuff 
Terry A. Davis improved the C language (Basically, Terry added some features and changed it so it's easier to use as shell language for TempleOS)

>>1611
They are probably still selling TOS t-shirts and mugs. Terry said it's ok.
Replies: >>7957
a_serb_in_his_habitat_and_with_his_winter_fur_on.jpg
[Hide] (141.7KB, 1024x693)
If you pick your programming language based on how small the statically linked hello world is you can't go wrong.

>>1596
All the mystification of assembly as some impossible god-level shit pajeets made really gets to one's head, makes me wonder what else they managed to sneak into my thoughts.
t. programs 8086 assembly with JWASM on DOS.

I'm not sure if Ken Thompson was held at gunpoint while he worked on Go or if age got to him, but when he made C he understood what programming meant. He wrote a language that simultaneously provides only abstractions that cleanly and efficiently map into assembly, and provides all the useful abstractions a programmer might want.
This is the definition of a good programming language that modern languages just don't understand. Modern languages are about enabling ignorance and hiding the machine away like it's evil.
C on the other hand shows you that after the machine has what it wants, you can have what you want too, but only if a skilled language designer makes that his goal.
Replies: >>1637 >>1644 >>1645
>unironically posting the trannyme book
shiggy.
Terry would call your shit out for being a FUCKING NIGGER
Replies: >>1631
david_wheeler.jpg
[Hide] (4KB, 148x185)
>pajeets made assembler
Why does the BO allow this diversity-hire tier glownigger shit here? Why hasn't he run them over yet?
Replies: >>1629
>>1628
>I can't read
>>1627
calm down, wigger. it's just a joke.
hapas are a joke. degenerate faggots are not, except as udderly cow fodder.
>>1621
>If you pick your programming language based on how small the statically linked hello world is you can't go wrong.
If everything you write is on that level, sure. I don't particularly care how my compiler optimizes trivial programs because that's not what I spend most of my time on.

>He wrote a language that simultaneously provides only abstractions that cleanly and efficiently map into assembly, and provides all the useful abstractions a programmer might want.
Except for overflow flags, proper strings and arrays, advanced control flow, useful macros, precise control over data layout... If you're looking for nonsense that silently sneaked into your thoughts, look no further than the deification that C went through. C was a product of substantial poverty (take a look at the machine Unix was made for) and perfectly appropriate at the time, but it's a joke of a language outside of that context. It wasn't even particularly efficient originally, all that came through later work and often clashed with the original design - that's especially visible if you compare K&R with the shameless pilpul over undefined behavior of today.
>>1621
>If you pick your programming language based on how small the statically linked hello world is you can't go wrong.
<small automatically == better
That depends. If you are on a tiny, tiny microcontroller or sensor where size is of utmost concern then sure, that's correct. However, most of us (and the rest of the world) care more about wallclock perf. In that case, increasing the memory footprint of the image in exchange for much, much higher performance is the proper course. Either C or C++ can allow you to make these kinds of tradeoffs, but few other languages can. Assembler doesn't count b/c I don't want to spend six months of my life managing to pull off something I can do instead in two seconds with -O3

As with all engineering, there are always tradeoffs to consider, with different ramifications. The only absolute guarantee we have going in is The 2nd Law of Thermodynamics. Beyond that, it's a progression of exploration & creativity. 

>tl;dr
Don't presume Anon, test.
GNU_face_when.png
[Hide] (841KB, 994x658)
>>1621
also
>but when [Thompson] made C
wew
>>1663
Soydev > nodev.
Replies: >>1665
>>1664
I'm inclined to disagree. There's a strong correlation between knowledge of computers and being a complete fucking faggot.
Replies: >>1667
>>1665
>taking pride in having 0 computer knowledge
As the kids would say: the absolute state of /tech/
Replies: >>1668 >>1669
>>1667
> write minecraft scripts
> ilook guys im a foking programer tech god
Replies: >>1671
>>1667
You should some pride in your reading comprehension if that's what you took away from my post.
>>1668
>14 year olds writing minecraft scripts are more computer-literate than you
Replies: >>1672 >>1889
>>1671
sippycup 4 drinkypoo pls
nenewithbook.jpg
[Hide] (84.3KB, 1191x670)
>>1671
>cute anime girls completely outclass you
I've read a lot of quality source code, gone through a book about proper practices, read plenty of good blogposts and talks by people over the matter, and learned at least this much.
Now I write really good code but can't come up with the most basic of programs.

rate
Replies: >>1905 >>1924
>>1903
>can't come up with the most basic of programs
What do you mean? Do you lack ideas or knowledge on algorithms/libraries?
Replies: >>1910
>>1905
Lack of knowledge on algorithms and libraries.
Also I'm extremely uncreative so I'll have trouble making anything I don't already know the recipe for.
Replies: >>1913
>>1910
then you never wrote shit or even tried to you idiot 
I spent years writing while( string[len] != '\0' ){ len++;} instead of strlen() and doing string manipulation by hand, until I discovered  strings.h, which was part of the fucking standard library the whole time, I never knew so  I broke my fucking balls putting str[end]='\0' everywhere while getting ptsd from memory corruptions and segmentation faults yet I still got shit done without any libraries
youre either lazy or fucking stupid, and theres no creativity involved, you write down the instructions and then translate them into code 
[what I want to do ] 
// print nigger x10 times
[ trying to figure out what code will do this ] 
printf() will print nigger, so put printf() into a loop for x10 
[ code ] 
for( i=0; i<11; i++) {prinf("nigger");}

wow, master coder
stop being a lazy nigger
Replies: >>1914 >>1926
>>1913
>I spent years writing while( string[len] != '\0' ){ len++;} instead of strlen() and doing string manipulation by hand, until I discovered  strings.h
What is wrong with you? Are you one of those subhumans who learn through Youtube tutorials?
>theres no creativity involved, you write down the instructions and then translate them into code 
Only for exceedingly trivial toy programs, you can't implement printf with that for instance.
>for( i=0; i<11; i++) {prinf("nigger");}
That will print nigger 11 times.
Replies: >>1916
>>1914
no a fat book that must be 50 years old or something that I never bothered to finish once I read the beginning , once I knew basic syntax I didnt bother to learn more, I could do anything I wanted which is the point, lack of knowledge is bullshit if you know the syntax because its just translating instructions at that point, I had to make my own libraries because I didnt know they existed, I even made my own version of sed and grep because I used them so much in bash and didnt know about the c regex engine I never cared because I immediately made them myself when I needed it, massive waste of time sure but I literally didnt know any better and just proves theres no excuse if all you is the basics
and it doesnt matter how complicated the software is, its always just a series instructions, a --> b --> c --> etc., doesnt matter how long or complex you make it, something has to happen when something else happens, if you know that then you dont need creativity or abstract libraries, you just need to know what has to happen and translate the instructions into code, in fact if creativity was involved then the fucking compiler wouldnt even work, by definition everything has to be a set of standardized instructions thats how computer works, anyone thats written assembly is probably more familiar with this mentality since there you really see what its like giving direct instructions 
its more logic and structuring , the only time you would be creative is in optimization  and EVEN there the compilers O2 flag will optimize the binary to near perfection so effectively there is zero use for creativity
>>1916
There is creativity in finding non-wageslave ideas, structuring projects and coming with with new algorithms. Once you get the idea pinned down, there isn't much creativity involved.
>>1916
>learning C through trial and error
>thinks optimization is code tuning
Imagine the UB
Replies: >>1920
>>1919
unironically yes
UB is my forte, its why I got into coding to begin with, I got into c only because I wanted to make hacks for CS1.6 years ago, started with hooking processes and manipulating memory addresses and then eventually more sophisticated ones using dll injection as I got better at coding, maybe thats why I dont give a shit about soydevs and soy programming, Im conditioned to think about actual runtime and not pseudo code 
made some cool malware too, a reverse tcp shell that used a priv-esc exploit that gave you full access(for winfail obviously) this was when msfpayload became popular with scriptkiddies and not even x86shikataganai would get you past gay antivrus because they spammed the msf fingerprint so much, so you had to make your own, and mine was sick could even turn the host into an ftp server to steal files or send goatse to set as the background, this was also when godamn adobe motherfucking flash, the virus of all viruses, was still considered safe 
those where the golden days, the days before soydevs
Replies: >>1921
I_can't_believe_this_story_you're_telling_me.webm
[Hide] (557.3KB, 490x360, 00:03)
>>1920
>l33t haxx0r
>can't even print nigger 10 times without getting it wrong
>>1903
I wouldn't trust an architect that's "gone through a lot of books" to build me a house, unless he has actually completed projects. If you're on Linux, there's so much unoptimized, barely working dogshit code in mundane utilities that you will be forced to think "why don't I just write this shit myself" every day. This will show you if your code is actually good, or just golfed into a working state on hello worlds or whatever the fuck you were writing that can't be considered basic programs. Or you can just get a job and do something else as a hobby, like 90% of normalfag programmers.
Replies: >>1929
>>1916
This might just be the dumbest thing I've read on this board.
Replies: >>1927
>>1913
>>1916
I've heard of mount stupid but this is truly out of the fucking stratosphere.
Replies: >>1927
>>1925
>>1926
N00b passing by, why is he stupid?
Replies: >>1928 >>1933
>>1927
he made a typo on the internet can you believe it
Replies: >>1936
sammies.jpg
[Hide] (121.6KB, 960x720)
>>1924
> If you're on Linux, there's so much unoptimized, barely working dogshit code in mundane utilities that you will be forced to think "why don't I just write this shit myself" every day.
Yes, I've seen plenty of it.

Retard-tier string manipulation. 
Dirty code bases with trailing whitespace everywhere, style violations everywhere. People who have never heard of enums and keep using the preprocessor for constants that fit an int. 
People who write all the functions with no top-level comment defining their interfaces so you have to read the function infer the details of the parameters and return values. Hueg source files full of obtuse code and with only 2 comments, those 2 comments spell out the obvious.
Using all the booleans at the same time. true/false from stdbool, their own #define TRUE and #define FALSE, and 1/0 integer literals.
Premature optimizations that make no sense. I've seen people use if-elses to get rid of modulo operations, I guess they heard modulo is slow..
Programs that are practically rewritten for every platform they run on. Huge #ifdefs and #elifs enclosing most of the source.
Garbage-tier file separation where there may be a file for graphics and another for sound but functions for those are everywhere.
People implementing a basic bitch binary search instead of using the stdlib, modulo as a hash function.

I haven't even gone through all that many projects.
I keep asking myself where those people learned C. I fix up quite a bit of code to gain experience and pad out contributions for a possible job, but the kind of people who make those mistakes are often the kind that will never recognize them or even care if they recognize them.


What do you recommend for learning to design bigger programs btw? I keep inching towards it but I'm not making particularly big progress. Reinventing the wheel daily is not really the way for doing those kinds of things, learning correct techniques from others is.
Replies: >>1931
>>1929
Lurk kernel mailing list for people shitting on other's code?
>>1927
Because he builds things by himself instead of listening and believing every single thing that soy drinking C++ enthusiasts from India who read books more than they actually program think. This is literally illegal and wrong and we should DOX and assassinate him to restore balance.
Replies: >>1936
>>1928
>>1933
Samefag harder.
You know, lately I've been swearing  a lot 
over some fucking piece of shit software
that has been over hype for more than half a decade. Look, if you gonna make a full featured software that is big and useful, at least make it less cumbersome and have no margin of shitty errors. For whatever reason, a lot of dev out there doesn't put enough effort on providing error exception logs or warning sign for end user to debug. When shit goes wrong, nothing useful error is being reported other than segfault. Because of that, users have to waste their time finding solution on the internet rather than able to fix themselves. Another thing is the UI design. Dear fuckhead, not everyone here run a 1080p resolution screen so why the fuck do you have to design a UI that is unscalable and big. A lot of these wasteful spaces could have been safe for the use of useful option button but no, they like to put the useless spaces there that has no use whatsoever. Fucking retard!
Replies: >>2012
>>2010
making something retard proof means you end up with thousands of lines of garbage checks throughout your code that make your shit unreadable and impossible to manage, its easier to just have a global "go fuck yourself [errorcode]" function for when the user is too stupid to read the instructions
Is it okay to talk about someone else's project, as means of motivation?
Replies: >>2017
>>2015
No. You're not allowed to talk about projects, including your own. You're only allowed to tell people that they're doing everything wrong and demoralize and blackpill everyone and everything in sight.
Replies: >>2031
roman.png
[Hide] (536.9KB, 1920x1050)
Let me tell you about what I consider to be one of the very well written programs I've had the pleasure of using; Persistence of Vision Raytracer, also known as POV-Ray.
This program was initially made in the late 1980s by one person, who was later joined by a handful of contributors, and released as "DKBTrace". That was back in a time when 3D software only existed as highly specialized packages that were business-oriented and too expensive for home users, the idea of a 3D program for the common man was completely alien. Enter David K. Buck, who made a 3D program that was not only free, but also open source and cross platform. Granted that it was a purely CLI program, it still compiled and ran flawlessly on MS-DOS, Unices, Macintosh, and Amiga, without any libraries or toolkits too. Needless to say the program was a total success.

So what was the secret? Good programming practices, nothing more nothing less. DKB wrote highly portable, strictly standard compliant code. He used proper indentation and documented all his files by writing comments inside them, while also providing clear and straightforward compilation instructions for every system. He also referred to theoretical books and academic references when implementing functionalities, and took inspiration from an existing raytracer. He used C, naturally, but that is beyond the point... All these practices carried on from DKBTrace to POV-Ray, the "rebranded" version of the program released in the early 1990s, which is still being developed today.

What's astonishing is that all these ancient pieces of software still compile on today's machines. I grabbed the POV-Ray 2.2 source from 1993 and compiled it with GCC, and to my surprise it compiled gracefully without spitting a single error. I was also able to compile the old DKBTrace from 1990/1991, after only a small tweak to the config file inspired by the one from 2.2... The reason I'm writing this is to bring attention to this beautiful piece of software as living proof that timeless code is very possible, and also to express dismay at newer pieces of software that are the complete opposite. Ever since I began my linux journey and started compiling other people's programs, I would often encounter extremely messy projects. Errors everywhere, heavy reliance on OS-specific code, lackluster or even outright nonexistent compilation instructions, dependence on obscure poorly written libraries or worse, dependence on custom versions of libraries that are no longer available...etc. It's particularly awful with recent projects, barely a couple years old and already aged like milk. We are living in a time where building robust code is easier than ever; cross platform libraries and frameworks, build systems, automated tests and what have you are all freely available, yet software is worse than it's ever been.

You have no excuse to make shit software. Learn from history and use every tool at your disposal. Write your code to be timeless... Otherwise you are part of the problem.
Pic related, rendered using DKBTrace.
Replies: >>2026 >>2027 >>2028
>>2025
>Good programming practices
Where can I learn it? Schools are useless, books are boring, just-code-it doesn't bring good programming practices. Am I supposed to read programs like POV-Ray to learn this?
Replies: >>2140
>>2025
That generally means you have to do more work yourself (as opposed to gluing together random libraries with minimal effort), and have discipline and high self respect, and most importantly taste for what's good. The way I see it, most programmers today are the programmer equivalent of mobile game players or fast food junkies. They don't have any taste for what's good and only see the very surface layer of things, aren't willing to put in extra thought or effort to get something of higher quality, will make excuses to justify their behavior and even put it on a pedestal like the better things aren't actually better or worth it.

I always try to make my programs as self-contained and self-reliant as possible, and not use any external tools besides the compiler. I only use libraries when there's some insurmountably complicated task which I could never competently do myself like parsing font/image files or videos.

There's a subtle art to writing simple code, I'm still learning all the time. I used to have weird naming schemes and I always wrote up all kinds of "systems" so I can re-use them later and mix and combine, but I've come to think that it almost always just overcomplicates the problem and often doesn't allow me to do what I need to anyway. The one thing I'm still struggling a lot with and currently working on is text rendering, I have various UI and text input systems but I want to get rid of most of them and just make something simple for text. It's hard to come up with something that's fast and simple and flexible though, like how do you organize text characters into a sprite sheet for the GPU, and how do you manage those spritesheets when you suddenly need some nippon runes?

Honestly I think the biggest problem is education. Even if I want to learn how to do X well, how am I supposed to find that information? Almost every program and game has text in it, yet I have no idea how to search for good ways to do text character rendering. I think in the past before the internet, you might think it was harder to do things, but I think it was actually easier because although it was harder to find information, when you found information you could generally trust that it's valuable. Now you have so much information that it's nearly impossible to extract the good information from the sea of shit and opportunists and agenda pushers and search engines giving pop culture results instead of something useful.
Replies: >>2028 >>2140
>>2025
The wonder of actual standards. I had a similar experience with a piece of Common Lisp code from the 90s and hear Ada is similar. People cannot shut their traps about how supposed "bitrot" means that everything must be maintained (read: go through regular churn) or magically stop working, but if you step back and think about it for a moment, it becomes immediately obvious that it isn't the program itself that is rotting but its environment. The problem is framed in a way that completely obscures its source so that the question "why is the environment changing to begin with" never occurs.

I saw the nature of this "bitrot" first hand when I had to run with an old version (4.9.4) for a while. Apparently at some point they decided that the default C standard should be changed from gnu89 to gnu99 or gnu11 (I forget which) because IT'S THE CURRENT YEAR. This is a completely pointless change that maybe saves someone somewhere eleven characters in a makefile, but instantly lead a bunch of retards to remove standard declarations "because we no longer need to declare C99", resulting in minor but completely pointless breakage to no benefit whatsoever. You may call it silly to get mad about this, but it's almost nothing but inane shit like this. No actual work is being done.

Programming has stopped being about automating work and has become a job creation scam. You still work the same hours, but instead of flipping physical levers you flip digital ones. Go through the changelogs of some software you use. How many changes actually eliminate work and how many are just stupid bells and whistles? Keeping up with pointless churn? Replacing old with new solely because the new one is shiny? Things that shouldn't have been in there to begin with but absorb hour after hour of programmer lifetime? It's depressing.

>>2027
>Honestly I think the biggest problem is education.
I agree. Classically this is the job of schools and universities - to cut out the noise and collect the signal - but anyone who's seen one from the inside knows they don't do that job anymore, especially when it comes to programming. I still remember the diatribe by MIT about how SICP is outdated "because programming is about trial and error science with libraries now". The CS sections of university libraries are lined with worthless schlock - what the fuck is jQuery For Dummies doing next to Knuth? It's civilizational rot, plain and simple.

As a result the top of the field is mostly made up of autodidacts, who are by their nature combative and constantly reinventing wheels. You see this attitude here on imageboards a lot, where people refuse to pick up a book out of principle. In a way you can't blame them, but at the same time it just perpetuates the problem. I have no idea how to combat it but dear god I'm turning into Uncle Ted with every passing year.
Replies: >>2029
>>2028
>refuse to pick up a book out of principle
What book do you suggest then?
Replies: >>2032 >>2035
>>2017
>blackpill everyone and everything in sight
Blackpill doesn't mean what you think it means.
Blackpill is a problem with no solution. It does not imply depression, suicide, violence or any other normie made-up crap. Anon, don't spread the normie crap.
>>2029
For what topic?
Replies: >>2036
>>2029
>actual standards
How to write timeless software and to structure programs.
t. college CSfag
Replies: >>2036
>>2035
meant for >>2032
What are some programming languages whose creators and lead developers are not fag worshippers?
Replies: >>2503
Working on a bulletin board to run as a shell with ssh access. Going to make a text converted image captcha for signup using aalib.

>>1557
>C++ is not suitable for embedded systems or resource (especially memory) constrained environments/software
>(Unless, you use "C-style" C++)
I know I'm replying to a 2 month old post, but this shit gets me mad as an embedded dev who uses C++. The real reason C++ "isn't suited" for embedded is because through the 90s and 00s no microcontroller producers were willing to maintain a C++ toolchain because it's so much more complex to implement than C. NOT necessarily heavier on the device! These day's you're hard pressed to find a MCU without a good C++ toolchain. C++ evangelists somehow get it into their head that C++ programs have to use half of the massive STL (not to mention boost) or else they're not using "real" C++. Sorry for the rant, it just seems like C++ fanatics try to actively discourage embedded devs from using it.

>>2026
Read well written programs. Write the best programs you can and then figure out how you can make them better.

>>2027
>Even if I want to learn how to do X well, how am I supposed to find that information?
Jesus Christ you sound like a whiny faggot. Boohoo there's TOO MUCH KNOWLEDGE on the Internet! Just start somewhere and you'll find your way to what you're looking for: read an ancient book, pick up a cutting edge paper, it doesn't matter; just GO! Stop being so goddamn helpless.
F.gif
[Hide] (18.4KB, 152x170)
G.gif
[Hide] (22.2KB, 193x151)
U.gif
[Hide] (20.1KB, 177x160)
>there's an esoteric mystery bug in a json parser I made months ago
>consistent but doesn't replicate itself in 2 different strings that both have the same structure
i-it's not like I wanted to dev anyway...
Replies: >>2483 >>2484 >>2487
>windows uploads files in the wrong order unless they're on the desktop
i-it's not like I was trying to spell anything with those letters anyway...
Replies: >>2483
fgu.png
[Hide] (85.9KB, 384x314)
>>2481
>>2482
FGU DXXXXXDXXXXXX D::D
>>2481
Memory corruption? Try changing up the test order.
r8bq16f0.jpg
[Hide] (136.9KB, 698x701)
>>2481
After a long and arduous journey, I found the problem and fixed it. I managed to narrow down the problem to where if I have 2 arrays, if the first one was long enough then the next one broke.

Turns out it was a good old array reallocation problem. I stored a pointer to the array node when I detected an array, and kept incrementing it's child count as I parsed more values. However if the node array needed more space for the child nodes and reallocated, the pointer to the parent array node became invalid.

I'm not sure how to stop making this mistake. I could use a different array type that creates new chunks when it needs more space (similar to C++ vector), but it's much more annoying to loop through because you need to use a bunch of verbose macros.
Replies: >>2488 >>2490 >>2504
>>2487
You can write your own vector in a header and only access it with functions. Some of them can be inlined to behave like macros.
Replies: >>2489
>>2488
I'm using C.
Replies: >>2492
>>2487
I don't think there is a way to avoid this other than just reminding yourself of this problem every time you reallocate something or trying to reduce the number of references to shit that tends to get reallocated. Actually there is, it's called garbage collection :^)
Replies: >>2491
>>2490
I just realized I could simply use a normal for loop with the second array type, and then use a get() function to get the correct item.
for (int i=0; i<array.count; i++) {
	Something* item = get_array_item(&array, i);
}My autism will probably prevent me from doing that though, because the get_array_item function would require some math vomit, so looping through with macros is more efficient. It would be better if performance is irrelevant though.
Replies: >>2493 >>2495
>>2489
Yeah, your own C version of vector or chunked arrays. You can check while inserting if the index is the last one, if so, expand it or create a chunk.
>>2491
Macro is tricky to get right, https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Inline.html#Inline is just as fast.
Replies: >>2494
>>2493
You can't use functions to loop through an array though, at least not without doing some convoluted callback shit. The code for looping through a chunked array without macros is something like this:
possible language: php, relevance: 8
int local_index = 0;
Array_chunk* chunk = array.data;
Something* item = chunk->data;
for (int i=0; i<array.item_count; ) {
	// code goes here
	
	i ++;
	local_index ++;
	item ++;
	if (local_index >= array.chunk_size) {
		chunk ++;
		local_index = 0;
		item = chunk->data;
	}
}
Replies: >>2496 >>2498 >>2504
Or alternatively this if you do >>2491
language: c
for (int i=0; i<array.item_count; i++) {
	Array_chunk* chunk = array.data + (pos/array.chunk_size);
	Something* item = chunk->data + ((pos % array.chunk_size)*array.item_size);
	
	// do something with *item
}
I just realized >>2494 doesn't necessarily work because if a new chunk is added during the loop then the chunk pointer breaks, you'd have to re-obtain the chunk pointer when you move to the next chunk. I haven't used that array much so I haven't run into that problem. I need to benchmark the different loops to see what the speed difference is, maybe the benefit is so miniscule that even my autism won't give a fuck and there's no reason to ever use the first one.
>>2494
>You can't use functions to loop through an array
You can.
language: c
Chunked_array* carray;
inline void** get_ca_chunk(array, n) {
	/* 
	 * Assuming you are storing chunks in an array
	 * 
	 * Also didn't do bounds checking, you can add it
	 */
	return (array->chunks)[n];
}
inline void* get_ca_item (Chunked_array array, i) {
	div_t q = div(i, array->chunk_size);
	/* 
	 * Assuming you are storing pointer,
	 * otherwise cast to char and do pointer arithmetic
	 *
	 * Also didn't do bounds checking, you can add it
	 */
	void **chunk = get_ca_chunk(array, q.quot);
	return chunk[q.rem];
}
for (int i = 0; i < carray->size; i++) {
        void item* = get_ca_item(carray, i);
        //Do something with item
}
Replies: >>2504
Array with 100k 4D matrices, chunk size of 32, 20k loop throughs (setting first value to 123)

For loop with get() speed; min 2375, max 3579
Macro loop speed; min 1042, max 4426

Array with 100k 4D matrices, chunk size of 16384, 20k loop throughs (setting first value to 123)

For loop with get() speed; min 2371, max 3993
Macro loop speed; min 971, max 4082

I don't know how to interpret these results. I did the tests 10k loops at a time, swapping their order for the other one, though it didn't seem to have a noticeable effect.
Checked the average speeds, get() method is about 2600 and macro method is about 1600. So it seems like the macro speed is indeed noticeably faster, not sure why it's so much more inconsistent though. How much the difference matters when there's actual code doing shit is another story.
>>2139
It's hard to argue invariably on this but C++ is mostly CIS White Males with extra privilege. I say this as a professional in the software industry, and relating to most of the men I work with. Zero obvious cock-suckers.

However, obviously a flaming faggot is the convener of the committee, at least one other is a well-known former author with a faggot lisp a mile wide, and as of last year, the biggest conference decided to literally trot young trannies out on stage to introduce the headliners. They even prop up a few token women now.

So the C++ community overall is very definitely under attack by the globalist kikes, but it's obvious that Bjarne doesn't think very highly of the faggots in the community, and again, in my experience in the industry we are practically all normal White men, a few Asian men, with just a couple of (much more advanced than usual) Poos in the mix.

But since it's a White Man's language (as is C), there's not a lot of reasonable propping up of incompetents. It's by and large still very much a meritocracy, given it's common type of use case/project development expense.
loops.png
[Hide] (4.4KB, 466x66)
Got curious so I did a slightly more complete test, 100k loop throughs this time. All arrays are separate from one another, and also pre-filled so there's no inserts or allocations or anything.
Flat array is the fastest possible dynamic array to loop through (as in there's literally no way to make it faster), it's the one I typically use since it's also the simplest, and also the one that I used in >>2487
Macro loop is >>2494
get() method is basically >>2498

I'm a little surprised that the chunk size has almost 0 effect on speed with the get() method, and that the bigger chunk size has bigger maximum times.
Replies: >>2505 >>2512
>>2504
Curious, did you inline get? If not, can you try that?
Replies: >>2506
>>2505
Yes it's set to inline. It's slightly different from your code though because my array includes item size.
Replies: >>2507
>>2506
My guess is division. Wrote a test with function pointers.
I probably did something wrong, the results aren't sane.

Output:
1000K Flat array: 0 s 8048413 ns
Test count: 1024000
1000K cs20 get() for loop: 0 s 12434219 ns
Test count: 1024000
1000K cs20 iterator: 0 s 4155361 ns
Test count: 1024000
Code:
language: c
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

typedef struct Chunk_array {
	int length;
	int chunk_size;
	void ***chunks;
} Chunk_array;

static inline void ** get_ca_chunk(Chunk_array *array, int n) {
	return (array->chunks)[n];
}

static inline void* get_ca_item(Chunk_array *array, int i) {
	div_t q = div(i, array->chunk_size);
	void **chunk = get_ca_chunk(array, q.quot);
	return chunk[q.rem];
}

void ca_iterator(Chunk_array *array, void (*fun)(void*)) {
	void ***chunk = array->chunks;
	for (int i = 0, j = 0; i < array->length; i++) {
		fun((*chunk)[j]);
		j++;
		if (j >= array->chunk_size) {
			chunk++;
			j = 0;
		}
	}
}

void * test_item = NULL;
long test_count = 0;

void nothing (void *item) {
	test_item = item;
	test_count++;
	return;
}

void time_diff (struct timespec *start, 
		struct timespec *end, 
		struct timespec *diff) {
	if ((end->tv_nsec - start->tv_nsec) < 0) {
		diff->tv_sec = end->tv_sec - start->tv_sec - 1;
		diff->tv_nsec = end->tv_nsec - start->tv_nsec + 1000000000;
	}
	else {
		diff->tv_sec = end->tv_sec - start->tv_sec;
		diff->tv_nsec = end->tv_nsec - start->tv_nsec;
	}
}

int main() {
	void **flat = malloc(1024*1000*sizeof(void*));
	Chunk_array *ca = malloc(sizeof(*ca));
	ca->length = 1024 * 1000;
	ca->chunk_size = 20;
	ca->chunks = malloc(1024*1000*sizeof(void*)/20);
	for (int i = 0; i < 1024*1000/20 ; i++) {
		(ca->chunks)[i] = malloc(20*sizeof(void*));
	}

	struct timespec start;
	struct timespec end;
	struct timespec diff;
	test_count = 0;
	clock_gettime(CLOCK_MONOTONIC, &start);
	for (int i = 0; i < ca->length; i++) {
		test_item = flat[i];
		test_count++;
	}
	clock_gettime(CLOCK_MONOTONIC, &end);
	time_diff(&start, &end, &diff);
	printf("1000K Flat array: %ld s %ld ns\n", diff.tv_sec, diff.tv_nsec);
	printf("Test count: %ld\n", test_count);

	test_count = 0;
	clock_gettime(CLOCK_MONOTONIC, &start);
	for (int i = 0; i < ca->length; i++) {
		test_item = get_ca_item(ca, i);
		test_count++;
	}
	clock_gettime(CLOCK_MONOTONIC, &end);
	time_diff(&start, &end, &diff);
	printf("1000K cs20 get() for loop: %ld s %ld ns\n", diff.tv_sec, diff.tv_nsec);
	printf("Test count: %ld\n", test_count);

	test_count = 0;
	clock_gettime(CLOCK_MONOTONIC, &start);
	ca_iterator(ca, nothing);
	clock_gettime(CLOCK_MONOTONIC, &end);
	time_diff(&start, &end, &diff);
	printf("1000K cs20 iterator: %ld s %ld ns\n", diff.tv_sec, diff.tv_nsec);
	printf("Test count: %ld\n", test_count);
}
Replies: >>2512
>>1410 (OP) 
Making my own software waifu/chatbot has been a long time dream of mine but I am afraid I have no idea where to start. Now that I have been stuck in the webdev rabbit hole, I am not sure if I will ever get to there at all.
Replies: >>2513
loops.png
[Hide] (11.6KB, 506x198)
>>2504
It occurred to me after going to bed that there was a couple flaws with those tests. Firstly a performance test isn't very relevant unless I compile in release mode, so this test is compiled with -O3.

Secondly I ran the tests on a bunch of 4D matrices, which are 4x4 arrays, in other words 16 floats or 64 bytes. With 20 of them each chunk is already 1280 bytes so it's not that surprising that chunk sizes didn't have much effect. So this time I included tests with 2D vectors which are just 2 floats. That puts each chunk at 120 bytes on the smaller case, but that's honestly already pushing how small chunks you'd use in reality, the default chunk size if you don't specify it is 64 items, so 20 is smaller than default. The gap between the macro loop and the get() method widened noticeably in the 2D vector arrays, with the macro loop being about 2-4 times faster.

Lastly I added a different version of the get() function, get2() uses the div() function instead of / and %. I thought get2() might be faster or similar, but it's a little shocking how much slower it is.

>>2507
It's pretty weird how you got a slower time on the flat array than the iterator. I can't see anything wrong, but I have 2 theories.

First theory is that since it was your first test, the CPU wasn't prepared to loop through a bunch of things, but some optimization kicked in after looping for a while. That's why I did each test 100k times.

Second theory is, I've heard that when you allocate a lot of memory, Linux doesn't actually allocate all of it, it only starts to allocate when you use the data. I don't remember exactly how that works so maybe it's not relevant. You could try looping through the array once before doing the test to make sure this isn't happening.
Replies: >>2517
>>2510
Just stop doing webdev and start learning about neural networks. I don't know anything about it so I can't point you anywhere though.
Replies: >>2515
Found the Linux memory allocation thing:
https://yewtu.be/watch?v=R5tBY9Zyw6o
10:00
>>2513
/robowaifu/ is probably the best start, as far as the webring goes.
>>2512
>lazy allocation
Looks much better now, can you do a test with function pointers?
1000K Flat array: 0 s 8392991 ns
Test count: 1024000
1000K cs20 get() for loop: 0 s 13340369 ns
Test count: 1024000
1000K cs20 iterator: 0 s 4698121 ns
Test count: 1024000
1000K Flat array pass 2: 0 s 2441695 ns
Test count: 1024000
1000K cs20 get() for loop pass 2: 0 s 9516012 ns
Test count: 1024000
1000K cs20 iterator pass 2: 0 s 4012364 ns
Test count: 1024000
Replies: >>2518
>>2517
Function pointer would just add the overhead of the function pointer, and I don't see a reason to do that, it isn't related to array types and just limits how you're able to loop through the array. The reason I call one of them a "macro loop" is because I'm using macros to do it, the actual code I have to write looks like this:
for_carray (&array, Vec2f, item) {
	item->x = 123;
	
	for_carray_next(&array, item);
}And the code for the macros are this:
possible language: python, relevance: 22
#define for_carray(a, type, name) \
	Carray_chunk* name##_chunk = (a)->data; \
	type* name = name##_chunk->data; \
	int name##_local_index = 0; \
	for (int name##_index = 0; name##_index < (a)->item_count;)

#define for_carray_next(a, name) \
		name##_index ++; \
		name##_local_index ++; \
		name ++; \
		if (name##_local_index >= (a)->chunk_size) { \
			name##_chunk = (a)->data + (name##_index/(a)->chunk_size); \
			name = name##_chunk->data; \
			name##_local_index = 0; \
		}
Replies: >>2524 >>2530 >>2580
Can't say I approve of this shitty "guess what programming language was in the code tags" feature.
Replies: >>2521
>>2520
you are intended to indicate which language the code s on the first line of every code block anon.

language: c
muh_C
language: python
muh_Python
http://crghlabr45r5pqkgnbgehywk5nxutdks5iss7tabyux5psikqqjirryd.onion/faq.html#2519
Replies: >>2522
>>2521
I know but it shouldn't guess the language because it always guesses wrong, it should just default to plain text.
>>2518
Right. I don't know enough macro to do it. The only reason to use a function pointer in this case would just be avoiding macros, unless you want to rewrite for loop into two inline functions, with the custom code in between. Probably would just be as bad as badly written macros at that point.
For anyone who's interested in C macros, here's a short description of them.

Macros are essentially just a text replacement, they don't do anything. You can put complete gibberish in the macro and it will always compile because it's just a text replacement instruction, not actual code. When you use the macro somewhere, that's when it'll break because it'll paste the gibberish into your code.
language: c
#define   fugger(a, b)   a = b

void main () {
    int x = 6;
    int y = 100;
    fugger(x, y);    // x = y;
    fugger(y, 6*10); // y = 6*10;
}The part where it gets complicated is when you use ##, which lets you attach text into the inputs.
language: c
#define   fugger(a, b)   a##foo = b

void main () {
    int x = 6;
    int y = 100;
    fugger(x, y);     // xfoo = y;      Error: 'xfoo' not defined
    fugger(y, 6*10);  // yfoo = 6*10;   Error: 'yfoo' not defined
}The reason I used it in >>2518 is because it allows you to stack loops. The loop needs several variables, and you won't be able to stack loops if the variables have the same names, so I used the item name to modify them. Instead of calling the chunk pointer 'chunk', I called it "name##_chunk", so when you send "item" into it as a name, it becomes 'item_chunk'. If you add a second loop inside it and send "second" as a name, then the chunk pointer for that loop would become 'second_chunk'.

I'm also sending a type into it, so the 'item' variable can have the correct type without requiring it to be cast separately.
language: c
#define   variable_one(name, type)   type name = 1;

void main () {
    variable_one(nigger, int);  // int nigger = 1;
    nigger += 100;
}
A macro ends with a new line, but you can make multi-line macros by escaping the new line. Just put a backslash as the last character on the line. It might be easier to read if you align the backslashes, but it's more annoying to edit.
language: c
#define   multiple_variables(name, type)       \
          type name##_x = 1;                   \
          type name##_y = 2;                   \
          type name##_z = name##_x + name##_y;

void main () {
    multiple_variables(foo, int);  // int foo_x = 1;
                                   // int foo_y = 2;
                                   // int foo_z = foo_x + foo_y;
}
Replies: >>2531
>>2530
retard
Replies: >>2532
>>2531
You got a better way to use macros?
Replies: >>2579
>>2532
Yes, not using them.
Build your binaries with LTO and for something that is not a library everything that can and should be inlined will be inlined. But don't forget to declare functions static just because of this.
Replies: >>2580
>>2579
How can I do the macro for loop in >>2518 with inlining?
Replies: >>2581
>>2580
I have no idea, your macro spaghetti is only better than an #ifdef forest.
Replies: >>2583
>>2581
>all macros are spaghetti
What's wrong about it except being a macro? How about you come up with a way to do it just as fast? Or everyone should just put on faggot socks and rust their dicks off because of muh safety?
I have an urge to code, but I never know what to code. I need to practice my C , but I don't know what I would want to code in C.
Replies: >>2594
1410758547451.jpg
[Hide] (278.1KB, 1261x1000)
challenges.png
[Hide] (1.2MB, 3840x2160)
>>2593
Replies: >>2595
>>2594
Thanks, I'll give it a try.
webring.png
[Hide] (208.6KB, 960x721)
Finally made some progress on something I've wanted to do for a long time: a program that shows webring boards.

It stores and organizes all the sites and boards into a local file so it doesn't lose any information if something fails to load, and obviously you can choose which sites to load in the first place. You can also color-code sites and hide boards, and it shows which boards were updated since the last time you checked (shown with bright outline). Favorited boards will show up above other boards when I make a better UI. There's also links to the catalog, but that too needs a better UI.
newposts.png
[Hide] (30.8KB, 961x112)
>>2601
I just realized that it's possible to show the amount of new posts since last update.
Replies: >>2603
>>2601
>>2602
What library are you using for the ui?
Replies: >>2604
>>2603
The "draw rectangles on the screen" library. You don't need one for something like this. I may use something when I make the UI better though.
Replies: >>2607
>>2604
Thought you are on Linux, there are much choices on Windows.
You can do framebuffer, xlib, xcb or even wayland on Linux.
Replies: >>2608 >>2613
>>2607
aren't*
>>2607
I don't care what the options are when I don't need any of them, it would just be a lot more work to interface with some bloated UI library.
Replies: >>2615
>>2613
A GUI library that isn't an exercise on how horrible software can get quite literally has never been written outside obscure hobbyist OSes.
Replies: >>2616
>>2615
>Good GUI library
Hard to do when all display stacks sucks and are unpenetrable massive blobs.
Replies: >>2618
>>2616
I looked at X source and saw unions of structs, I closed the file and never dared to look into that codebase again.
wrk.webm
[Hide] (4.1MB, 1208x900, 00:35)
>>2601
Made a better UI. If you click the board description it takes you to catalog, not sure if there's a better place to put that link. The favorite star doesn't do anything, it just makes it easier to spot the boards you care about the most (it's also meant to become bright white when there's new posts, but looks like I missed adding that).

There's still a few minor things missing, such as showing a notification when someone added a new site to their webring follow/known list (so you can learn about new members and add them to your list if you want), showing the full description/title when you hover over it (currently it just clips out if it doesn't fit), and ability to use a different sorting method (pph/users/etc). It also opens a CMD window for a split second when you click a link because I just call system("start url") to open the links, I'm not sure what a better way to open links would be. Maybe calling the browser executable directly instead of 'start', but I have no idea how to dynamically find out where the executable is (or what browser is the default in the first place).

I encountered a crash at one point. Curl seems to create new threads that get stuck on, and every time you refresh the board list it creates even more threads and/or crashes, I don't understand why. I'm not doing anything wrong as far as I can tell, and I'm error checking the curl functions. Curl #includes windows.h and fucks up my main function as well by the way. This kind of shit is exactly why I don't want to use anyone else's gay libraries. I'd make my own HTTP requests if I didn't have to deal with the cancer that is TLS.
index.gif
[Hide] (10.9MB, 1100x580)
>>2619
>>2601
wow nice
>>2619
wow, its shit
>>2619
Have you seen https://zzzchan.xyz/boards.html
Replies: >>2625
>>2624
LOOOOOOOOOOL
>>2619
I found the crash, turns out it is indeed Curl. It happens when I call curl_global_cleanup for the second time. I really don't have any idea what I'm supposed to do about that except keep it initialized, but that sounds gay. I could create a separate program and launch that, but A) that's also a pain because now I need 2 separate programs, and B) I don't have enough experience with interacting between processes like that so I don't know how to do it properly. Like I have no idea how to send an integer from one process to another, or if it's even possible in the first place, I need to be able to know which ones succeeded and which ones didn't.
Replies: >>2632
>>2628
>know which ones succeeded
On Linux, this is done by forking and wait(2). Windows should have their version of this.
>ipc
Forked process on Linux can share memory space until there are changes. The parent can set a variable right before forking and the child can see it. Other ways to interprocess communication are pipes, sockets, shm/mmap, sysv ipc, posix msg queue and signal.
GIhF.gif
[Hide] (1.8MB, 282x278)
I learned to do proper color blending with alpha. It's a lot more confusing than it seems because if you draw with 50% opacity on top of 50% opacity, the result is not 100% opacity, it's 75%. And if one of the colors is pure red and the other is pure green, the result is not 50% green and 50% red, it's 66.6% of the upper color and 33.3% of the one below.

I'm probably calculating the result in a retarded way and there's a much smarter way of doing it, but it works. Pic related is 2 test images being drawn on top of each other, and then the result being drawn on top of a background.
Replies: >>2783 >>2790
>>2782
why are you multiplying percentages
use a float and just add them
Replies: >>2784
>>2783
I don't understand what you're saying. A "float" multiplied by 100 is a percentage.
Replies: >>2785
>>2784
exactly,
i = 0.5 + 0.5; i % 2; i *100
how are you getting 75%
Replies: >>2786
>>2785
>how are you getting 75%
It doesn't matter, that's the correct value. If you have a sheet of glass with 50% transparency, and you look at it through another sheet of glass with 50% transparency, you can still see behind both of them.
Replies: >>2788
Working on a textboard script. I might upload a sample sometime soon. All I have left to do is add bumping, saging and security and it would be functional but no one would use it until I polish it
>>2786
Transparency: 50% * 50% = 25%
Opacity: 1 - 25% = 75%
He is talking about opacity, not transparency.
Replies: >>2789
>>2788
Opacity and transparency are the inverse of each other, it's the same thing.
GIF.gif
[Hide] (1.9MB, 294x293)
>>2782
Trying to SIMDify it and ran into an interesting visual glitch.

I'm struggling to figure out how to cast 32bit ints into 8bit ints in SIMD. It kind of doesn't seem possible. I can make this work by manually extracting the 32 bit ints one by one and casting them down, but that seems silly.
Replies: >>2884
sections.webm
[Hide] (1.7MB, 1200x800, 00:23)
>>1549
>5 months ago
I got slightly distracted I guess.

Continuing this, I've been working on a UI sectioning system for the past several days so I can organize panels onto the screen. I had a lot of difficulty figuring out how to do it, but turns out it became very easy when I defined in literal and very specific terms what I want to happen in any given situation.

I want each panel to have an absolute minimum size that it can't get below (so the panel contents won't become hidden). I also want the ability to scale the panels to a desired size (so you can resize a layer list for example). Some panels also need to stretch to fill the unused space (for example canvas, maybe layer list). If the desired sizes aren't enough to fill the screen, then the panels that have stretch booleans set will expand to fill the remaining space. If the desired sizes do not fit into the screen, then all the panels that haven't reached minimum size are shrunk. If even the minimum sizes do not fit, then all panels are forcibly scaled down, this isn't "supposed to" happen but it's a failsafe so the UI is less likely to go off-screen. I may add a hard-coded forced minimum size of 50 pixels or so to prevent the panels from shrinking to an unusable size.

Width and height work slightly differently however. The width is always shrunk to fit the screen (as described above), but the height has 2 modes (configurable based on user preference). In the first mode, if the panel desired heights do not fit the screen, then that column will get a scrollbar and you can scroll it down like a list of panels. In the second mode, the panels are scaled down towards their minimum size if they don't fit, and only get a scrollbar if the minimum heights do not fit. The first mode has more user control over panel sizes, and the second mode tries to avoid creating scrollbars.

This is great progress because now I can start adding actual controls to the program.
Replies: >>2934
>>2790
https://www.felixcloutier.com/x86/vpmovdb:vpmovsdb:vpmovusdb
is probably the instruction you are looking for.
for future reference the website is nice and contains every x86 instruction.
Replies: >>2902
>>2884
>AVX512
You need a CPU from the last few years to have support for that, and Intel is apparently dropping support for it for new CPUs. It sounds like what I want but I don't want to use AVX512.

>for future reference the website is nice and contains every x86 instruction
The Intel intrinsics guide is also good:
https://software.intel.com/sites/landingpage/IntrinsicsGuide/
Replies: >>2951
auto-height.webm
[Hide] (791.7KB, 1204x760, 00:15)
>>2862
As I started working on the tools panel, I immediately realized that the panel's final width may change it's minimum height and it's not completely straightforward to make that work. I had to change some things to account for it which wasn't a huge deal, but it was enough to demotivate me for most of the week.
Replies: >>2935
stretching_problem.png
[Hide] (58.4KB, 1030x960)
>>2934
Just discovered another problem, and this time I'm not sure how to solve it. If a column is taller than the window, it's supposed to have a scrollbar. However, if any one column is taller than the window, it's going to stretch everything else to be taller than the window as well, so the whole screen would end up getting a scrollbar.

It gets more complicated if for example the top tool bar was stretched across the whole screen, then you couldn't treat the right column as it's own thing. It would be hard to determine which column should get the scrollbar.

My first theory is that when stretching things vertically to fill available space, I should use the window size as a limiter, so they can't stretch any further than that.
Replies: >>2936
stretch_fix.webm
[Hide] (668.8KB, 1006x744, 00:14)
>>2935
>My first theory is that when stretching things vertically to fill available space, I should use the window size as a limiter
Well that worked easier than expected.

The left toolbar still goes offscreen because of unrelated reason; it's attached to a column instead of a row. That's something I planned to change anyway (such that panels can only be in rows) so it'll fix itself at some point.
Replies: >>2940
swatches.webm
[Hide] (2.5MB, 1060x774, 00:30)
>>2936
Added some color swatches. Video compression messes with the colors so they look a bit wrong on the canvas in webm.
>>2902
according to autists in forums taking die shots Intel reached a point in useless meme instructions to fake benchmarks with where the meme instructions take most of the die area and they could win the CPU wars for a while if they just tried to beat AMD honestly instead of adding more deadweight.
img1.jpg
[Hide] (19KB, 380x187)
i made a db thing for all the games i want to play because i'll play them all for sure.
sorry for the blurry pic but i can't reveal all the details to the feds. they have to work and not play my games.
timer.png
[Hide] (4.7KB, 270x294)
I keep forgetting to drink water for an entire day and shit, so I made a program that plays a sound every hour.
Replies: >>2973 >>3281
flash.png
[Hide] (28.5KB, 187x283)
On that note, what should I call the function that flashes the taskbar icon to get your attention?

request_attention_in_taskbar() ?
window_ask_for_attention() ?

I can't come up with anything that sounds clear. I want to avoid using the word "flash" just in case some other operating system does something else, like show a notification icon.
Replies: >>2957 >>2959
>>2956
taskbar_notify()
Replies: >>2961
>>2956
guibell

t. unix guy
Replies: >>2961
>>2957
'Notify' sounds a bit like it's going to open a popup or something.

>>2959
That's no good for multiple reasons.
Replies: >>2963
>>2961
How about taskbar_beckon(), then?
Replies: >>2964
>>2963
That sounds interesting. Might use something along that line.
>>2955
Here's a download.
https://tsun.itch.io/hourlysound
I ended up using it to do hourly push ups.

I tried to port it to Linux but I don't know how to install SDL since I can't get internet on my Linux computer.
1616298500309.gif
[Hide] (2.3MB, 498x498)
Holy shit I've been on a tangent for a while now because it annoys the fuck out of me how big my program executables are. I just can't get the filesize to go down no matter what I do even when the program barely fucking contains anything.

I just looked at an executable with a hex editor again and found some fucking function names in there that are never even close to being used in the program. I've tried every possible combination of -s,  -Wl,--gc-sections,  -fdata-sections,  -ffunction-sections,  -fno-data-sections,  and -fno-function-sections, but nothing fucking works. Then I figured the compiler is broken so I downloaded one from a different souce and the filesizes are completely different. An empty project goes from 300 kb to 50 kb which was exciting at first, but then I tried to compile an actual project and it went from 500 kb to 1 mb, and some of my projects don't even compile because of some fucking multiple definition conflict that ever existed before.

I'm so close to throwing all of this shit into the trash and writing my own programming language from scratch that outputs assembly. Or I would but I have never before in my life managed to get an assembler working because it literally just never works even when I do the literal exact thing down to the atoms that a guide tells me to do. So rather than outputting assembly, my compiler would output x86 machine instructions.
>>2974
Sincere advice: Get over your ricer phase. There are things that are actually worth optimizing down and executable size isn't one of them, especially when you're in the 1MB ballpark.
What language/compiler/stdlib are you even using?
Replies: >>2976
>>2975
That "ricer phase" will never end, it's part of my personality to be in control of my things and not accept bullshit.

>What language/compiler/stdlib
C, GCC (MingW). I've spent plenty of time trying to figure out how to remove C standard libraries and still be able to actually do things, but it's like looking for a needle in a haystack. Removing libc makes the executable go to 5 kb and compile so fast that it looks like it doesn't even happen, which was a dream come true until I realized nothing actually works.
Replies: >>2978 >>2979
>>2976
Have you tried tcc?
Replies: >>2981
>>2976
>That "ricer phase" will never end, it's part of my personality to be in control of my things and not accept bullshit.
You don't seem very much in control when you struggle with an Assembler, have your project's headers barf on a different compiler, and don't understand why a C program doesn't work without libc - but what do I care.
>C, GCC (MingW)
Tough luck, as far as I know there aren't obvious switches you could try like glibc -> musl on Linux. If you want to bypass libc you'd have to start looking into your platform's ABI; Windows' should be pretty stable and documented due to backwards compatibility and reversing, but mostly you'll just waste your time doing shit by hand that C already does for you.
Replies: >>2981
>>2978
I don't care about filesize so much that I'd destroy my program's performance.

>>2979
>struggle with an Assembler
What the fuck do you expect me to do? I'm following the instructions to a T and it just doesn't fucking work. There's exactly 0 results when I try to search for help because nobody uses assemblers these days except people even more autistic than me.

>project's headers barf on a different compiler
It was because of some operating system functions that the compiler links differently.

>why a C program doesn't work without libc
I know why it doesn't work. I want to know how to make it work. I wouldn't think it's such obscure thing to do that I have to start learning some assembly interface from scratch, I might as well just start writing my own compiler if I need to go that deep.
Replies: >>3002
sigsegv.png
[Hide] (6.7KB, 640x129)
Testing some new debugging utilities. I can now track the current call stack, and detect when there's a memory overflow. This also allows me to add profiling later so I can check what functions take the longest in my program. My favorite part is that none of this requires any external tools.

It's a little surprising how many function calls there are when you can see it happen. I guess it's also the fault of Windows terminal being slow, but my program goes to like 0.5 FPS when I enable function call printing.
>>2981
>I don't care about filesize so much that I'd destroy my program's performance.
Then stop this obsession because chances are you will not wind up with ANY program if you continue down this path. You are not as clever as you seem to think you are, and your struggle to find resources in the most knowledge saturated environment ever should clue you in to that fact. It's fun to let loose in low level occasionally, yet you need the programming chops to back it up. I wrote a brainfuck compiler straight to machine code once; it produces tiny executables, but I know it sure as fuck isn't optimized. To prove my point I'm going to drop a minimal Linux Hello World that compiles down to about 1k with GCC on my machine and show you some sources so you can choose to masochistically cargo cult your way through low level hell. I'm giving you rope, go hang yourself faggot.

First the makefile, we'll want no standard library and a custom entry point because the default involves the c runtime setting up flags. Found the options on stackoverflow:
> https://stackoverflow.com/questions/67516597/gcc-passing-nostartfiles-to-ld-via-gcc-for-minimal-binary-size
> https://stackoverflow.com/questions/7494244/how-to-change-entry-point-of-c-program-with-gcc
all:
	gcc -nostdlib -eentry -s -static -n main.c
Now the program. Just a quick wrapper around a couple syscalls. The arguments are the same and implicitly in place because of the ABI.
> https://hackeradam.com/x86-64-linux-syscalls/
> https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI
possible language: c++, relevance: 19
void mywrite(int fd, const char *str, int len) {
        asm(
                "mov $1, %rax\n"
                "syscall"
        );
}

void myexit(int err) {
        asm(
                "mov $60, %rax\n"
                "syscall"
        );
}

void entry(void) {
        mywrite(1, "Hello World\n", 12);
        myexit(0);
}
Replies: >>3004
>executable size
oh, check out plw/geimu/ thread, I've suffered with it since forever. Or read this.
https://hero.handmade.network/forums/code-discussion/t/94-guide_-_how_to_avoid_c_c++_runtime_on_windows
If you program for linux, I recommend programming for wine. Fuck linux. There is a link to the linux version of that thread somewhere in comments.
Replies: >>3004
>>3002
>you will not wind up with ANY program if you continue down this path
Yeah, except I'm practically the only one in this thread posting my programs. When I make a program like >>1535 and I know I could probably cut the executable size in half or less and improving compile time by a similar amount just by removing useless shit that I don't need, I'm obviously going to want to do that. Someone already complained that it was suspicious when one of my program's executable size inexplicably jumped up like 50%: https://anon.cafe/make/res/161.html#q179
I still don't really know why it happened, maybe I updated my compiler somewhere along the way and that caused it. My only theory besides that is, I figured out recently that there's some bug(?) with IF blocks in batch files and that may have dropped a part of my compile string. Either way I want to be in control of this stuff and I don't want random shit to be inserted into my program.

>quick wrapper around a couple syscalls
I can kind of read assembly, but since I never got an assembler to work, I haven't been able to learn it much so I don't really understand how/why that works. I'm also primarily on Windows so I can't try that right now. The main issue I have is that when I link with Windows API functions, none of them work. Even if I know how to write to stdout or something, I still wouldn't know how to get the rest of the operating system to work.

I'll write that down though for when I use a Linux machine, so thanks either way.

>>3003
I saw that, but it seems bound to MSVC, I couldn't get it to work on GCC.
gcc is shit, it adds a little string that says something like "compiled with gcc version this", use microsoft compilers. Or at least digital mars c++ is somewhat tolerable, but ancient. There is pelles C or something like that, but eh. There is clang, the worst thing I can say about it is internals of it are weird (it adds yet another intermediate language besides assembly), and nothing but microsoft compilers can do SEH well. There is ZIG language, but you cannot be both crossplatform and perfect, easier to do two different versions that share some cpp files.

I'm planning to upload a tiny gdi program in a few weeks, could be useful as a reference.
Replies: >>3006
>>3005
I don't plan on downloading Visual Bloat Spyware Studio so I could compile my program. I'm going to use the compiler that lets me download it and then use it, and a third party GCC build is the only one that let me do that.
Heh. I wasted years on GCShit, when I should've used proper IDE and proper debugger, they are really unvaluable.

Download visual studio 2005 at least, it is still relatively usable. Also don't download free version of new visual studio, it will force you to register later, steal an enterprise version instead.

Also you keep using the word "GCC", you sure you don't mean Mingw?
Replies: >>3008 >>3009
>>3007
>idefag
Do you even know what Mingw is? It's built for windows linux binaries, it comes with gcc.
Replies: >>3009
>>3007
I strongly object to installing programs like Visual Studio on my personal computer, and I don't like adding more tools into my workflow. Also as >>3008 said, MinGW is like a package that contains GCC.
It doesn't come with gcc, it's a port of gcc for windows. It's about as shit as gcc, but still much better than cygwin. Cygwin dependencies are impossible to remove while using that compiler, mingw dependencies are possible.to remove.

gcc debugger is a barely functional thing, while in visual studio it just works. It may be a good idea to use visual studio for development, but make your code compatible with smaller compilers.

People keep talking about visual studio code, sounds like a very cut down version, I never tried that.
Replies: >>3011 >>3013
f9fb2714814ca4b9e2d82fc400678d2859a9848696326931aa6ac00344742f2c.jpg
[Hide] (35.2KB, 720x540)
>>3010
>sage
>thread still on top
Why are you so dumb? Anyone using sage is an edgy moralist anyway.
Replies: >>3012 >>3013
>>3011
shutup newfag
>>3011
>edgy moralist
hownew.ru
>>3010
You problem is more likely due to working in a toy os designed by street shitters for retards who never programs. Of course nothing works on that piece of crap. My gdb just works. You need mingw, cygwin, wsl all those shitty wine-for-fags just to use bash or gcc or install this 5gb bloat burger nigger to use a glorified notepad, compiler and file manager that loads in 5 minutes. But wait there is dark theme :3! And you can play your jew games on the same OS!!!!111 Not to mention you never need to learn about what compiler flags are and how any of that shit works. What a steal.
Have fun reading about all the 500 useless compiler switches gcc provides and 50 defacto dead architectures it for some reason still supports. Waste your time, I don't mind. Everything gcc does, visual studio does less painfully.

I have no idea why new visual studio is so heavy. I'll just say "this is a tool for professionals that can afford good hardware and keep it open all the day anyway", though it's a bad excuse. I think first launch takes about 2 minutes, every following launch is faster. I pretty much open it once and never close it.

Again, visual studio 2005 express is pretty neat for older computers.
About how to make tiny exe on windows with mingw. I just googled "mingw freestanding".

https://nullprogram.com/blog/2016/01/31/

You can't use stdlib and exceptions anymore, but you still can use winapi and SEH. Not sure about SEH though.

On linux, yeah you can fuck with syscalls all you want, but even loading a library in this way is a really complicated task that just requires adding libc or one of the smaller alternatives of libc. Linux just wasn't made with binary compatibility in mind, you have to recompile everything every time some faggot decides it's time to deprecate some shit.
Replies: >>3017
Ah, if only microsoft faggots weren't trying to kill pc gaming and visual studio to the boot. I heard rumors of microsoft paying developers to not release their games on windows, and going all in on xbox. Visual Studio 2019 free version gathered telemetry and one day just suddenly forced me to register with microsoft account, which I just couldn't do for some reason. And I heard there is no free version of Visual Studio 2020. Yeah, just pirate that shit.
Replies: >>3017
>>3015
>||Freestanding|| refers to programs that don’t link, either statically or dynamically, against a standard library (i.e. libc)
Thanks, hadn't heard of that term before.

>>3016
>Visual Studio 2019 free version gathered telemetry and one day just suddenly forced me to register with microsoft account, which I just couldn't do for some reason
This kind of shit is exactly why I avoid using anything more than the bare minimum and why I avoid most mainstream programs.
Has the stupid text formatting ever worked correctly on this fucking imageboard engine?

'aaa'   aaa  'aaa'  ||aaa||   aaa   aaa   aaa   `aaa`
sec18-quach.pdf
(465KB)
>>2974
What you want to do is not possible with an ordinary compiler as far as I know, so it's useless to golf your flags. You might be interested in this concept though: https://www.usenix.org/conference/usenixsecurity18/presentation/quach
Replies: >>3040
Untitled.png
[Hide] (260.9KB, 1040x481)
Holy shit I want to stop using itch.io. Is there any other place you can upload your programs to? I don't care what it is as long as you can make a page that describes the project and has screenshots, and isn't a git page.
Replies: >>3034 >>3035
>>2974
Are you using mingw? There are some broken mingws around.
>>3032
Indiestand runs on Google services, but it's new enough to be free of pozz. They don't have any kind of payment system, so your game has to be free. https://sites.google.com/view/indiestand
IndieDB is run by fags, but it's not itch.io. Yet. https://www.indiedb.com/
>>3032
You can use something else (eg jew-drive, mega, torrent) to store your program/source and neocities for site.
>>3024
It's possible, but not on linux. Because linux is shit.
Replies: >>3041 >>3053
>>3040
You mean embedded firmware can't be compiled on linux?
>>3040
The fucking board ate my PDF. Do you mean in general? Because the presentation I linked states
>Our solution can successfully compile and load most li- braries on Ubuntu Desktop 16.04
Or is it due to the prevalence of dynamic linking?
Replies: >>3054 >>3063
>>3053
He means he is a winfag who can't properly config/build a toolchain so he must rely on vendor supplied shit to just werk.
>>3053
>On linux, yeah you can fuck with syscalls all you want, but even loading a library in this way is a really complicated task that just requires adding libc or one of the smaller alternatives of libc. Linux just wasn't made with binary compatibility in mind, you have to recompile everything every time some faggot decides it's time to deprecate some shit.

Also I didn't watch that presentation, it's too long. Somebody should make a better executable format, a loader, and apis that aren't garbage for linux. SDL2 is somewhat acceptable, but opengl is garbage.
Replies: >>3078 >>3083
>>3063
>opengl is garbage.
What about Vulkan? I've heard it's a big improvement over OpenGL.
Replies: >>3079 >>3122
>>3078
If we're talking about how good an API is, then Vulkan significantly more garbage than OpenGL. It's clearly designed by the same kind of retards who jump into bandwagons every month and think OOP is the gold standard of programming and write 70 times more code than required for any given problem.
Replies: >>3080 >>3088
>>3079
>cluesess cnile decides that shitting up /g/ wasn't enough
Replies: >>3117
>>3063
>Also I didn't watch that presentation, it's too long
Then skim the PDF, it's 13 pages of two column text. It outlines several limitations and problems when doing this that I hoped someone would shed more light on if they're experienced with C and looking at the resulting binary it produces. The most annoying problem is probably the bits of assembly.
>Somebody should make a better executable format, a loader, and apis
>SDL2
Am I talking to a GPT? What the fuck are you talking about? SDL is not a graphics API, it is a platform independent wrapper around them. Which means it has zero use as a graphics renderer if there is no OpenGL, DirectX or Metal on your system. Secondly, I still don't understand how a new executable format and all that other shit would solve the problem of compilers including unused bits of code from the main program and libraries associated with it.
Replies: >>3118 >>3122
double_facepalm.jpg
[Hide] (36.3KB, 640x480)
>>3079
I agree with you anon. When I first read that there was this new Vulkan thing I was thinking they were going to fix all the Opengl clusterfuck api. Then I saw the documentation, and they clusterfucked it even more than I thought was possible.
f7719264ed78aea7ef9aaf968f087b989b9e8474d35bfc6dc26208d2b03c7073.png
[Hide] (177.6KB, 1050x828)
>>3080
Seeing "senile" spelt that way is viscerally disgusting. It's like I'm looking at someone infected by a disease, someone who wants everyone around him to feel as sickly as he is.
Replies: >>3119 >>3121
>>3083
>the problem of compilers including unused bits of code from the main program and libraries associated with it
is this even real
I thought the compiler tosses out dead variables and functions when statically linking
Replies: >>3123
>>3117
>nooo don't mock me for fanboying C without understanding it
Maybe you should stop and wonder why you're praising OpenGL, a garbage fire that is now officially deprecated, against Vulkan, a complicated but effective tool that is actually used in the industry.
Replies: >>3120 >>3121 >>3133
>>3119
I wonder if you're purely baiting or if you legitimately can't see the irony in what you're saying. Vulkan being a horrid pile of shit has nothing to do with OpenGL being good or praiseworthy.
Replies: >>3148
>>3117
>>3119
Stop. One mention of the language that begins with L and ends with p and you're going to summon HIM.
Replies: >>3124 >>3127 >>3148
>>3083
>Then skim the PDF
Skimmed through it. Looks like it tries to improve already existing linux programs, simply by recompiling it in a more smart way. So, it tries to soften the impact of bad code, while I want to rip it the fuck out. It doesn't mention elf format being shit, and in fact adds even more sections to it. Well, linux gonna linux, it doesn't concern me.

>What the fuck are you talking about? SDL is not a graphics API, it is a platform independent wrapper around them.
SDL1 is everything api, including graphics, file io, sound, keyboard/mouse. But it can't do 3d hardware accelerated graphics, so SDL2 uses opengl for that. I don't mind SDL1 as my main api, it's pretty neat and small. I still would rather use winapi, simply because it already works, and I don't want to break something that works just fine. And because linux doesn't seem to have anything like VirtualAlloc, I wonder if there are any patents involved or something. And because exe ends up smaller if you use lower level apis directly without any dll or libraries in between.

>>3078
>What about Vulkan? I've heard it's a big improvement over OpenGL.
No idea. I noticed that using OpenGL on windows machine resulted in first launch of that program taking about 10 seconds, while Direct3D9 program loaded instantly. That probably had something to do with Firefox using Direct3D9 on my computer, so it is already loaded when I try to use Direct3D9 in my own program. I think OpenGL also shitted up main heap with some trash. I assume Vulkan does something like that too, plus it only works on windows 7 and older.

I'm going full monkey and abandoning even the thought of ever writing a high performance 3d game, so I don't really need additional performance Vulkan provides. I'm trying to aim for compatibility with older hardware instead. So, I'm limiting myself to Direct3D9, it is good enough for 2d platformers and maybe simple 3d games. Vulkan is in the realm of big studios and serious engines, it's not an area I can compete in.

I actually kind of started to like Direct3D approach compared to OpenGL once I understood how it works. Every OpenGL function you use, adds a string with its name to the exe file. While with Direct3D, the only string that gets added is Direct3DCreate9. That's some clever shit, this function returns to you an array of functions you can use, some of which return yet another array of functions. Unlike C++ which doesn't have a stable binary api, DirectX uses COM (Component Object Model), which explicitly states how each such thing is going to behave. You can even use it from C if you want to. It's more painful though, so you better not, you have to call something like IDirect3D9_CreateTexture(d3d9, width, height) instead of d3d9->CreateTexture(width, height).
Replies: >>3123
static_dynamic.png
[Hide] (94.3KB, 1500x844)
>>3118
>I thought the compiler tosses out dead variables and functions when statically linking
It's an approach meant to compromise with the already existing environment of everything being dynamically linked. Basically adds a loader that strips out extra code based on a dependency graph. Gains compared to statically linked code are negligible, pic related.

>>3122
Not necessarily recompiling, more like peeking inside what happens during the compilation process itself and gathering data for the loader, which is why it's based on LLVM and clang.
>It doesn't mention elf format being shit, and in fact adds even more sections to it
I'm assuming you mean that it's shit compared to EXE/COM. In what way?

>SDL1 is everything api, including graphics, file io, sound, keyboard/mouse
I should've been more clear. SDL is, as the name states, a layer. It's convenient and, relatively speaking, easier because you have a saner abstraction level above raw OpenGL and DirectX calls. Can't really replace anything with it, because it is just that.
>using OpenGL on windows machine resulted in first launch of that program taking about 10 seconds
Windows refusing to play with NIH technology is not surprising, especially if it's 7 or lower.
>So, I'm limiting myself to Direct3D9
>it can't do 3d hardware accelerated graphics, so SDL2 uses opengl for that
I thought SDL 1 and 2 both have DirectX backends?
Replies: >>3126 >>3128
>>3121
But what if I want to summon him? I loved his posts and the pure anal pain they caused.
>>3123
>>It doesn't mention elf format being shit, and in fact adds even more sections to it
>I'm assuming you mean that it's shit compared to EXE/COM. In what way?
No import section. Elf format forces you to do syscall magic to get your libraries. With PE, you just list libraries you need to load, functions from said libraries you need, and os does this aaaal for you. Elf way is more annoying, it takes more space, and it is less maintainable.
Also you can't run 32bit executables on 64bit processors on linux for some reason. Maybe you can, but it's not as easy as doubleclicking it.

>I thought SDL 1 and 2 both have DirectX backends?
DirectDraw backend maybe. It's still 2d only.

>I should've been more clear. SDL is, as the name states, a layer. It's convenient and, relatively speaking, easier because you have a saner abstraction level above raw OpenGL and DirectX calls. Can't really replace anything with it, because it is just that.
All SDL2 does is opens a window for you.
Anyway, API is Application Programming Interface. I call SDL an API because it is Interface I use when Programming an Application.

LISP. HAHAHAHA, SUFFER FAGS
Replies: >>3141
>>3121
tbh you can't deny that the APIs (in  this case OpenGL and Vulkan) are messy and complex because of the typical Cnile mindset aka "worse is better" (instead of doing the right thing)
Replies: >>3133
>>3123
>It's an approach meant to compromise with the already existing environment of everything being dynamically linked
this makes no sense
so its literally just static linking because the loaded libraries are impossible to share between programs since the address space for functions would be totally different for each program compiled with a modified library
this feels like a solution( not really ) to an artificially made up problem that only exists in hypothetical scenarios that do not even exist, like an os that runs only a single tiny program thats dynamically linked to a large library
Replies: >>3130 >>3141
>>3128
The "problem" is that dynamic linking is fucking stupid, and rather than get rid of this idiotic idea that was originally introduced to deal with the bloatshit that was X11. Just look at the arguments the authors list against static linking:

>Requires recompilation of binaries with every library or software update.
This is a lie, it only requires relinking which is easy to automate. Package managers have existed for decades now.
>Does not allow memory sharing across processes.
This is a lie, instances of the same process will still share memory. It's only different programs using the same library that don't share code, but the code removal also (substantially, as the very same study shows!) decreases the size again. That said, none of this even matters with current resources, we're talking about code size for fuck's sake. This was relevant for the bloated interwoven spaghetti shit that was X, which was also the original reason dynamic linking was even invented.
>May result in accidental violation of (L)GPL.
Nobody cares.
>Increases binary size compared with dynamic linking.
Yeah because the metric conveniently excludes the size of the dynamically linked code. Turns out women have less debt than men if you don't count debt by women. Who'd have thought?
>Risks transferring bugs in a shared library to the binary.
Just like dynamic linking can silently introduce regressions to previously known-good programs, but somehow this part never counts for anything.

Another fun one you hear often is "but static linking can't do ASLR". Then you ask why it can't do ASLR and it turns out that the only reason is that when they added ASLR, it was convenient to use the dynamic linking mechanism for it and they said "well, static linking is bad anyway and nobody uses it" and made no effort to add compatibility with static linking.

I don't even blame the authors personally for this, dynamic linking is basically a religion at this point. But god fuck am I sick and tired of the mountain of ever more complex "solutions" that narrowly avoid solving the actual problem, which is rather simple.
>>3130
<and rather than get rid of this idiotic idea that was originally introduced to deal with the bloatshit that was X11, they keep adding stupid "fixes" that don't solve the issue.
>>3130
made me wonder why isnt there a kernel level solution that does on the fly dynamic-dynamic linking for userspace processes 
like it would buffer loading the program into memory and replace functions that are identical and already loaded in memory with an existing pointer instead of loading duplicates
this way you wouldnt need to load the entire library into memory and instead gradually "build" the library into memory as more and more shared functions get called while also purging library functions that are no longer being used
downs.png
[Hide] (75.1KB, 229x318)
>>3119
>>3127
>if you don't like my godawful forced meme you like C and OpenGL
>>3130
iirc Multics had a pretty sane approach to dynamic linking (it's been a while since I looked into this, so I can't give too many specifics), but said approach required memory segmentation and the vast majority of CPUs nowadays are designed around memory paging and, if I recall correctly, so are most operating systems including Unix-based ones.
>linuxproblems
>>3126
>Also you can't run 32bit executables on 64bit processors on linux for some reason
I don't think the underlying architecture that allows doing this on Windows is simple.

>>3128
I guess it's a stopgap solution for when you are stuck with dynamic linking but also need to reduce code footprint. One thing to also note is that this makes startup times really slow.

>>3130
Actually, Linus agrees with you at least when it comes to userspace: https://lore.kernel.org/lkml/CAHk-=whs8QZf3YnifdLv57+FhBi5_WeNTG1B-suOES=RcUSmQg@mail.gmail.com/

>Another fun one you hear often is "but static linking can't do ASLR"
But it can https://drewdevault.com/dynlib
>We've had ASLR for statically linked binaries for some time now. It's called static PIE.

A source-based distro with more of a focus on static linking could be an alternative to Gentoo, less load on the package manager that way too.
Replies: >>3149
>implying worse isn't better
>do the right thing no matter the cost
If you machine always do the right thing, it would be bloater than your mum. Getting to the point where only the essentials are implemented makes  the implementation simple. It is easier to implement, debug and understood.
>>3120
>Vulkan being a horrid pile of shit
According to who?
Some contrarian nocoder on a dead board?

>>3121
I don't even like that language with the L, I don't even hate C that much, I just hate clueless retards that worship C as some kind of RETVRN TO TRADITION.
Replies: >>3152
>>3141
>>We've had ASLR for statically linked binaries for some time now. It's called static PIE.
Sweet, I didn't know about this because I stuck with GCC4 for so long.
C/C++ is eh, but everything else somehow managed to be even worse.
>>3148
>I don't even like that language with the L
I think it's one of the best languages out there, because of the (lack of) syntax. Particularly the one with the S because it was designed to be more sane and minimal.

>RETVRN TO TRADITION
Well, it is at this point, at least for high-level languages. And of course, almost all good software is still written in C (and a lot of terrible software too, of course) while it's safe to say that other languages mostly produce a bunch of crap, and trying to replace C would be a disaster because you know that it would be done as poorly as humanly possible and it would be replaced with bloated garbage written in a bloated and retarded language, designed to give corporations as much control as possible. As imperfect as old tools and standards may be, people today are too retarded and evil to replace them, so we're better off not doing it. There are a lot of changes that I would really like to see, but for now, fix humanity first, then the tools, or the tools will be corrupted and ruined.

For now just accept that C isn't successful because it's perfectly designed to give you whatever unnecessary features you want (that most people would only use to make a bigger mess), it's successful because it's small and simple and only gives you what you need and nothing more, and it has been resistant to change, so it's reliable and stood the test of time. It's not successful because of what it does, it's successful because of what it doesn't do and hasn't done. It requires a little more competence, but that has the benefit of repelling idiots, to some extent. The morons are all working on bloated trash written in Python or whatever it is that they do. Do you really want them working on your kernel? I don't.

Other languages, on the other hand, almost always become so complex that they can't possibly replace a language like C well. Nowadays, the average developer wants to maximize complexity, so when they attempt to replace C, the result is the abomination known as Rust.
Replies: >>3154 >>3156
>>3152
>designed to give corporations as much control as possible.
How would you design a language to give a corporation control, and over what?  That doesn't even make any sense.
> it's successful because it's small and simple and only gives you what you need and nothing more
The first part, sure.  The last part, no.  If the system I'm building would benefit from using object oriented programming, why wouldn't I use a language that supports it instead of hacking something similar to it in C?
Simple tools aren't useful for building shit that's inherently complex.  It's not that you can't do such a thing, but you're going to open yourself up to memory leaks, dereferencing null pointers, and other unexpected behaviors if you're not careful.  And just saying "be a better program" is idiotic since nobody's perfect.
>but that has the benefit of repelling idiots, to some extent
Or maybe they realize that they can write better software in a different language that supports the abstractions they need, with the benefit of not needing to worry about lower level shit when they don't have the resources to do so.
>The morons are all working on bloated trash written in Python or whatever it is that they do. Do you really want them working on your kernel? I don't.
no, but python and C are two completely different use cases.  Most people aren't going to write their websites in C.
> the result is the abomination known as Rust.
Can you give some examples of what's wrong with rust, pushing aside everything about the rust community?  Just as a language.
I personally don't see rust replacing C because there'll always be low level cases where the whole "memory safety" shit can't apply, but if it's not some kernel level shit I think there's a use case.
Replies: >>3155
>>3154
Not him, but
>Simple tools aren't useful for building shit that's inherently complex
A problem I have with things outside of the C/C++ field is FFI and general language interop since I don't know much about it. Even with C++ libraries you'll run into issues with exposing their functions to other languages because of, for example, templating. Is this better in Rust? C is pretty much the gold standard for integrating it into other systems at the moment.

Say I write a complete piece of software in Lisp or Rust. Now somebody decides that a piece of my program's functionality would be good to use in another language. Can they do it without any major issues?

>Can you give some examples of what's wrong with rust, pushing aside everything about the rust community
I think it's fine, aside from it not being as portable as the C family. There are also problems with following the bootstrap chain up until the latest Rust compiler because of LLVM, so you basically have to trust the binary official sources are distributing. The guy maintaining Sabotage Linux was complaining about that one. Not something wrong with the language itself, more of a Trusting Trust problem.
>>3152
>Particularly the one with the S because it was designed to be more sane and minimal.
In practice, this "sanity" and "minimality" ends up in you reimplementing half of Common Lisp in a more ad hoc way. See Guile for a particularly egregious example of this in action.
>And of course, almost all good software is still written in C (and a lot of terrible software too, of course) while it's safe to say that other languages mostly produce a bunch of crap
You pulled this straight out of your arse, but even if it was true it wouldn't matter. It's just the "but so many good sites use PHP" pseudoargument.
>trying to replace C would be a disaster because you know that it would be done as poorly as humanly possible
What kind of fatlogic is this? Never change anything bro, improvements aren't possible. A major reason why you have so many specialized languages is that C sucks and their authors wanted to get the fuck away from it. The issue is that they usually only fixed the few parts that bothered them the most or didn't have an actual design in mind beyond "I just want to program".
>[C is] successful because it's small and simple and only gives you what you need
What if I need overflow checks? Or vectorization? Or bounds checks by default that I can selectively disable in hot paths because disabling those by default when 1% of the code is responsible for 99% of the runtime is retarded? Or actual arrays? Or control flow in the vein of CL's restart system? It's not even simple. Try writing down the semantics of pointers some time, they are mindblowingly awful. The "simple" C you think of is your obvious implementation of C (because the language definition is optimized to make that conforming), but that's not the implementation you're actually using and hasn't been for a decade or two. Undefined behavior based optimizations send their regards.

C is successful because it's established (so unless you want to break with the ever increasing ball of legacy shit you'll need C support at some point) and extremely primitive (easy porting => first one to market). It also provides absolutely nothing for sane interop, so replacing it is obnoxious. No, C interop is not good, vendors just had to standardize on an ABI for the most urgent necessities because otherwise nothing would work at all, and C doesn't provide many features beyond those necessities. Those it does provide don't reliably work. Passing structs by value? Fuck you. Bitfields? Fuck you. Constants that are defined as macros and depend on preprocessor shit? Fuck you, have fun basically reimplementing half of C if you want to support that. Supporting the absolute basics is not an achievement.

>Other languages, on the other hand, almost always become so complex that they can't possibly replace a language like C well.
Of course they're not going to be a replacement for what C programmers want, but that's because what C programmers want is fucking stupid and if you make something like that you'll basically just end up with a different C that sucks just as badly. Once you start actually handling errors, the simplicity and elegance of C vanish in a puff of smoke.
>the result is the abomination known as Rust
I'd really like to know what parts of Rust you hate (there are certainly enough to last a lifetime), because most Cfags who hate Rust seem to hate it for the most idiotic of reasons. Usually that the language actually forces them to think about errors and lifetimes, and won't let them pajeet pointers all over the place, or that they don't feel like a 1337 h4xx0r when using it because there are safety mechanisms. There was a similar hatred for Ada back in the day, and it had no tranny cabal or language instability.
Replies: >>3157 >>3167 >>3174
>>3156
Actually Ada did have an equivalent of "muh trannies" back in the day, now that I think about it. "Muh military".
>>3156
it really shows that you don't grok C, therefore you don't like it, therefore it's broken.
you should read more about where C comes from, why it was made that way, how it evolved and why it's kept the way it is.
it's not perfect, but it's definitely not broken.
Replies: >>3173
>>3167
I probably know more about all of that than you do. That your response to all arguments is the equivalent of a commie going "read a book" is telling.
Replies: >>3201
>>3156
limitations are universally bad youre taking control away from the programmer, how are you this stupid
good programmers dont want training wheels and you cant become a good programmer if you rely on training wheels
Replies: >>3175
>>3174
And yet you piggyback off your compiler's calling convention. What's the matter, do you suck too much to write the function prologue by hand every time? Come back when you've taken off the training wheels, india boy, this board is for actual programmers.
Replies: >>3176
>>3175
thats trivial
memory control and void pointers are not
Replies: >>3177
>>3176
Confirmed for never looking at any assembly output by a compiler, but that was obvious given the blind C fanboying and that you think void pointers are somehow special. If memory control is non-trivial, why aren't you letting the computer assist you with it? Is it because you
>don't feel like a 1337 h4xx0r when using it because there are safety mechanisms
?
Replies: >>3178
>>3177
calling conventions are trivial
if dont understand why void pointers are special, then youve never done memory mapping, good luck trying to make any kind of efficient data structure in rusticle retard
What about C#
Replies: >>3203
>>3173
so in your opinion, i'm telling you to get informed on something i don't know anything about? doesn't even make sense.
also, i was in the cracking scene more than 20 years ago, so no, i don't have to learn anything from you.
Replies: >>3202
>>3201
Yeah, just like the commie doing it makes no sense. We can compare e-dicks all day, or you could address the actual arguments. Hopefully in a better way than the other retard who thinks void pointers are magic and optimizing calling conventions is trivial rather than intractable.
Replies: >>3220
>>3184
>What about C#
Microsoft's clone of Java.
Java has a larger FOSS community (with tooling and libraries) which is why I would pick Java instead of C#.
>>3202
I did address the arguments, you started the "commie" ad-hominem.
my argument was (and still is) that you are using C wrong. car analogy: you can't use a car like a boat, so you say the car is broken.
the fact that you say you know the history and purpose of C better than me (or whoever else) is clearly false or you wouldn't point out problems that are not there.
if you want me to argue in detail, again, read the history and purpose of C, my arguments  are there.
and now for me is case closed.
Replies: >>3224
>>3220
This may surprise you, but "no u just don't understand its genius, making retarded tradeoffs is actually good because i say so" is not actually an argument.
Replies: >>3378
ct-amtrak-train-derails-vermont-20151005.jpg
[Hide] (791.8KB, 2048x1360)
I warned you. I told you not to summon him.
Replies: >>3227
>>3226
I haven't even reached 10% of his autism output. Check your bounds properly and nobody gets hurt.
activity.png
[Hide] (8.3KB, 295x295)
Making a program that tracks how long you've been paying attention to programs, so I can (hopefully) learn to waste less time on the internet. It just grabs the active window, finds what the process executable is, and increments a counter for it.
Replies: >>3317
Untitled.png
[Hide] (11.1KB, 367x298)
Now shows 2 different global timers, one for all the programs, and another for how long the timer has been running. Some programs aren't counted such as the "UNKNOWN" and the timer program itself, so you could use the program itself as a pause of sorts.

I think I'll combine this with >>2955. I've wanted to make a proper timer program for a long time, but I never thought about the ability to tie timers to program usage.

I wonder if there's a way to detect mouse/keyboard input without the window being active and without running some loop at 20000 fps. Supposedly Windows has some kind of hooks system but I don't know how it works. It would be cool if I could detect actual activity, so I could make separate timers for window focus time and actual activity time.
Replies: >>3304 >>3363
N00b C question:
Why should I ever use "normal" data types if int_fastN_t or int_leastN_t do the same thing?
>>3284
That's actually a good question.
A pedantic answer would be because those types are optional whereas int, char, and so on are not.
Replies: >>3294 >>3303
>>3284
I never found them to make any difference, they're probably only relevant if you're compiling to some unusual platform.
Replies: >>3294
>>3284
Readability, mostly. Outside of some really specific scenarios (largely involving intN_t and intptr_t), these types are basically useless.
Replies: >>3290 >>3294
>>3289
Isn't int_fastN_t more readable than long long/long/short? The byte is on the type.
Replies: >>3294
>>3284
>>3285
>>3286
>>3289
>>3290
> Why should I ever use "normal" data types if int_fastN_t or int_leastN_t do the same thing?
> Isn't int_fastN_t more readable than long long/long/short?
Types such as  int_fastN_t are, or can be, a bit different than int/long int. It may have different size (optimization). I recall C Primer Plus, 6th ed. by Stephen Prata had a section that discussed the differences of various type specifiers. For example, int8_t is always 8 bits. See https://en.cppreference.com/w/c/types/integer for reference.
Replies: >>3295
>>3294
I understand the difference, but normal data types are "at least N bytes long", which is the same as fast and least except I can choose to be small or fast as well.
>>3284
it's most likely pre-optimization.  If you're program is too slow without these types, you're probably doing something wrong on a much more fundamental level.
>>3285
I think int_Nt was optional but not the least or fast variants.
Though I think this was only introduced in C99 if that's what you meant.
Untitled.png
[Hide] (3KB, 270x80)
>>3281
>keep it up for a while
>think I've been pretty productive so far
>not even 40% of my time spent paying attention to useful things
I hate this program.
Replies: >>3305 >>3383
>>3304
>sublime
install vim
Replies: >>3310 >>3338
>>3305
I cannot think of a much less interesting and less useful thing to waste braincells on.
Replies: >>3335 >>3336
>>3280
This sounds fun, I might try that myself.
>>3310
>tfw too inteleglent to learn anything
>>3310
Leave it to a Windows user to make such retarded posts.
>>3305
What do you use vim for? I've come back to it several times, and each time decided it was a mess. I recently looked into macros to see if they'd be useful, but I came to the conclusion that I never need anything that general purpose in editor. Replace/sed and the shell commands cover those rare cases fine, and no editor I know of actually supports semantic replacement rules (as in, aware of scopes and types), which is what I actually want. Unfortunately vim seems to be promoted heavily by the same kind of autists who think that studying functional languages makes them a wizard. Not to say that it isn't good at anything, but I don't see a lot of people who just write code talking about how much better it is. Ultimately I just use it as a less ergonomic editor when I need to use a text mode editor.
Replies: >>3342 >>3350
>>3338
I use vim for everything (except fucking java).
>never need anything that general purpose
It's bloat. But the bloat doesn't affect the startup time and run time much. Most users, including me, probably don't use and even know half of the function. It is fast and easy to use enough after learning about 10 keystrokes.
>>3338
Vim is good for just editing text. Startup time is instant, text objects are great, modal editing is voodoo but for large amounts of successive commands it's great and things like vimdiff and autocmd hooks are just plain useful even when you only use them occasionally.
If you want an IDE that does fancy IDE things, you could make it in vim if you were autistic enough. I know neovim now supports lua by default and every other language by plugin, so you don't even have to work with vimscript.
Ultimately, if you have a text editor that just works for you, there's no reason to switch, but if you do vim will almost never be a bad choice.
timetracker.webm
[Hide] (1.5MB, 1280x800, 00:16)
>>3281
Made a better UI for it. It's now possible to create groups and timers. Timers can be attached to groups or programs, or they can be global. The lock allows you to make a timer or tracker stay active, so you could for example create an empty group and use it to manually track non-program related things.

Didn't actually add sounds yet, ran out of time for today. Also need to make an interface for modifying the timers and groups, currently they're hard-coded. A more involved thing I kinda want to add is sessions, such that all the times will be saved from the last time the program was up, you can click a button to start a new session, and can view old session times. Not sure if I'll bother to add it for now though.

I managed to optimize the program so that ProcessHacker shows 0 CPU usage even though the timers keep updating.
Somewhat related to that, it turns out Windows has a very easy way to track mouse events when you click on the window and drag off-screen. I used to use very ugly and complicated ways to handle that myself, so cleaning that up feels pretty good. All you need to do is call SetCapture() when mouse is pressed, and ReleaseCapture() when mouse is lifted.
Replies: >>3367
flashy.webm
[Hide] (1.2MB, 734x700, 00:17)
>>3363
Sounds can now be tied to timers, though webm is muted because I can't find the setting to enable audio recording in ShareX. The timer will also flash until you click the screen, or until 1.5 seconds after focusing the window.

I'm getting to the unfortunate part where this already does what I want, so I don't have a lot of motivation to finish it by making groups/timers user-configurable. Maybe I'll just keep the program for myself.
Replies: >>3368 >>3387
>>3367
>Maybe I'll just keep the program for myself.
You can just say that is configurable by editing the source (like Suckless stuff)
tablet_photo_rescale.jpg
[Hide] (761.5KB, 1125x1500)
>What are you working on?

>last project
>have 10+ year old pen tablet
>plug-in but no drivers
>find foss Linux kernel drivers for it
>compile 
>still doesn't work
>can't tell what the problem is
>crash while trying to figure out the problem
>write libusb driver to see if the device isn't broken
>it works
>add hotplugging
>put up a fundraiser that didn't ask for much
>get more than I expected

I might buy some used pen tablets of the same series just to support them. This is a fairly unknown brand however (compared to wacom/cintiq).

For now, I'm doing random programming challenges in Ada.
Replies: >>3386
>>3224
i'm not surprised by your strawmanning what i never said.
also, thank you for providing a list of problem C has, along with the sources of those technical decisions made by the iso workgroup, compiler vendors and whatnot, and your arguments against them.
see? if you do your research you'll find most criticising is just an exercise in ignorance.
keep the quality posting going.
time.png
[Hide] (7.1KB, 354x114)
>>3304
It's weird, as soon as I start this program, I get motivated to do stuff because I don't want to let the shameful counters build up. Still not as good times as I'm hoping for though.
>>2974
You might be also interested in the Linkers And Loaders book.

>https://nathanotterness.com/2021/10/tiny_elf_modernized.html
Like the article I take for inspiration, I set out to create the smallest ELF file that runs on modern Linux

>www.muppetlabs.com/~breadbox/software/tiny/teensy.html
A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux
Replies: >>3385 >>3413
>>3384
neither of the articles are written by me
4073324eaa58bc8a56cea638104c565e955395b3.gif
[Hide] (481.6KB, 640x480)
>>3371
Great work, anon!
>>3367
Added a settings file so timers and groups and such can be configured. There's still a few things I'd like to add like the ability to sort the list by time, but I'm anxious to get to working on other stuff.

Here it is:
https://tsun.itch.io/timetracker
>>2974
>>3384
Can't you just use -Os or -Oz and compress the executable?
Replies: >>3415
>>3413
Ignore, he's a Windows pajeet doing static linking.
Replies: >>3454
>>3415
>Being a dynamic fag
Replies: >>3457
a8cc7fc876e33debffb66d2f4c8198073bd895f0084b474716f462eaaa173e75.png
[Hide] (398.9KB, 762x990)
What is the truth!?

> Static Linking Considered Harmful
https://www.akkadia.org/drepper/no_static_linking.html
< Dynamic Linking Considered Harmful
http://harmful.cat-v.org/software/dynamic-linking/
https://en.wikipedia.org/wiki/DLL_Hell
http://users.eecs.northwestern.edu/~kch479/docs/khale_rtld_2-7-2013.pdf
https://gavinhoward.com/2021/10/static-linking-considered-harmful-considered-harmful/
https://ro-che.info/articles/2016-09-09-static-binaries-scientific-computing
(https://catonmat.net/ldd-arbitrary-code-execution)

* Also read Linkers and Loaders: https://www.iecc.com/linker/ and Programming from the Ground Up: https://savannah.nongnu.org/projects/pgubook/
* https://www.usenix.org/legacy/publications/library/proceedings/usenix05/tech/general/full_papers/collberg/collberg_html/main.html
Replies: >>3461 >>3462
>>3454
I use a good build system and a good programming language where I can just flick a switch and get either and the binary won't have any unused functions.
Replies: >>3460
>>3457
>moving the goalposts
>>3455
in my honest opinion, programming (especially C or C++) is much more enjoyable in GNU/Linux, but I think dynamic linking is a mistake.
Replies: >>3463
>>3455
>https://www.akkadia.org/drepper/no_static_linking.html
See >>3130.
>>3461
There are some small time efforts at a Linux with a static base, for example Oasis and Sta.li. Both seem to expect getting software not yet supported (which is 99.9% of it) with Nix's package manager. But to really take it further would require an architecture similar to Arch Linux build servers and NixOS ones, where build artifacts for each package would be kept for easier relinking. This would also have the potential to truly decouple some programs from potterware, especially systemd.
Replies: >>4262
Why do people say C bit fields are not portable? What is not portable about them?
I know there's some implementation defined behavior when you make a single bit signed field, but that's basically it isn't it?
Replies: >>3471 >>3473 >>3485
>>3470
oh yeah, and it's implementation defined if say an "int" bit field is unsigned or signed, but really, it's easy to get around all of that and it should work the same everywhere.
>>3470
They mean the memory layout is unpredictable. C actually makes very few guarantees about that and it just happens to work for most cases because the language is so primitive there's often only one way to do it.
Replies: >>3486
>>3470
They are not portable because the ordering of bit field is not specified. The compiler can store it in any order, regardless of endian. The problem is storing bit fields in files, they can only be safely read by the same program on the same architecture.
Replies: >>3486
>>3473
>>3485
I see. Well, that's easy to serialize, but more code than using the standard integer types and bit banging them by hand and then serializing the integers if needed.
Wrote a small CL library to decrypt and extract DxLib archives (notably used by WolfRPG and a bunch of obscure weebshit) without the key. Was fun, but it once again confirmed my prejudice that game developers are retarded gorilla niggers and have no idea what they're doing. It's 1600 LOC so I'm not posting it directly.
https://felswerfer.de/pastebin.php?id=19bce00a5e80b7fa72ca
Replies: >>3503
>>3488
I've tried writing an extractor for a game file format once and the format was just wtf-tier.

They had repeated fields, unused fields that the game's machine code didn't read or write (and I'm guessing the data in those fields was uninitialized memory from the programmer's machine lmao), they even had useless fields like files with pointers to their directories even though the directories already pointed to the files.
Replies: >>3508
>>3503
>they even had useless fields like files with pointers to their directories even though the directories already pointed to the files
They probably did something similar to DxLib: Load the file straight into memory with absolutely zero input validation, and then interpret it as a data structure at runtime. Infuriating to deal with.

Another mindboggling thing DxLib does is pointless compression that suggests the author doesn't understand anything about the topic. For instance, the eighth version of the format will Huffman encode the first and final few KBs of a file. This adds a shitload of complexity to shave off a few KB as the theoretical maximum - in practice files become LARGER that way. Just… why?
Dancing_Terry.gif
[Hide] (2.6MB, 300x424)
Take the Tcl pill
shamelessly reposting this:
Tcl is the best scripting language for the real but still productive hacker
(Scheme is not far).

* Extremely small - whole syntax/grammar is described in 12 rules in a single
  man page (Tcl(n)) of 150 lines and there's no reserved keyword.

* Official man pages! No pydoc or cppreference garbage, here you almost have C
  degree of exhaustivity.

* Kind of "unfashionable" language meaning basically no poz.

* At least two implementations with jimtcl being a very thorough embedded one.

* One of the simplest if not the simplest interaction with C, letting you write
  C plugins very easily (with critcl, ffidl and swig to help).

* Comparable in speed to cpython, a bit slower than Perl5 and Lua. Has a
  and a WIP/dead LLVM compiler (tclquadcode) for a big speedup in the far and
  uncertain future.
  https://wiki.tcl-lang.org/page/Tcl+Performance for more.

* Cool type system that is superficially "everything is a string" (like sh)
  but in reality "everything is a tagged union with on-the-fly conversion when
  needed and a unique string representation". Allows for some very cool things
  like editing dictionaries as lists or lists as strings and transparent
  serialization (puts $mydict $chan <=> set mydict [read $chan]).

* Talking about types, multiprecision arithmetic is transparently handled,
  allowing you to do expr {42 ** 1000} if you just want to.

* Very powerful introspection through info (mainly). Allows for stuff like
  getting the name/body/arglist of a procedure, get all the registered
  procedures, know if a variable exist, get information on the stack frames and
  their content, etc...
  Together with trace, you can write an internal debugger in few lines. See
  https://wiki.tcl-lang.org/page/Full+program+trace+onwards for an example.

* Procedure arguments are passed by pointer with a copy-on-write system: don't
  modify the argument and you don't get any memory copy. To you, it just looks
  like regular passing by value.

* On the subject of performance and simplicity, no need for an actual garbage
  collector, reference counting is enough because you cannot make circular
  references.

* Modifying the procedure arguments is done via upvar: in Tcl, a variable
  reference is just a name (string) with a stack frame number, quite elegant
  considering the language's concepts.

* If you use at least the builtin extensions (thread, http, tdbc, tcltest,
  msgcat) and the very basic tcllib/tclX/tclUdp/tklib packages, you're almost
  set for life. Personally, I also use the very convenient tclreadline, tdom,
  pipethread and tclcurl.
  Some more here: https://core.tcl-lang.org/jenglish/gutter/

* Channels is the cleanest I/O implementation I've ever used with some cool
  features:
  * Transformations allowing filters like deflate/zlib/gzip or TLS to be put on
    a channel (see transchan for the API).
  * Reflected aka virtual channels, to make a channel without an actual backing
    FD. Basically like glibc's unportable fopencookie.
  * Centralize all ioctl/fcntl shit and even more (like defining the EOF char).
  * Integration with the event loop via chan event allows for a nice callback
    oriented approach to sockets and pipes.
  * Other third-party channel types include pty (expect), random, memory or
    fifo (memchan).

* Builtin event loop (see after, vwait, socket -server and chan event)
  for powerful and seamless concurrency/command scheduling.

* An elegant thread extension consisting of an interpreter per thread and no
  raw access to other thread's memory. Comes with both simple (thread) and
  performant (tsv) synchronization/communication facilities.

* Finally a sane, light and portable (even more with Tile) GUI toolkit: Tk.

* One of the fastest unicode aware regex implementations, written by Henry
  Spencer himself. Has its own greater-than-POSIX-ERE syntax called ARE, not
  as complete as PCRE (lacking lookbehind constraints, most importantly),
  but still great for an hybrid NFA/DFA engine.

* uplevel (execute a script in a different stack frame) and tailcall
  (replace the current procedure with another command) let you augment the
  language by implementing control structures and keywords yourself. Basically
  CL macros, but different (less powerful than CL's synergy between "naked AST"
  style homoiconicity, symbols as first-class objects and quasi-quoting, but
  not seen as different from functions, that you can't pass to map in CL).

* Safe interpreters let you do very fun things like config files in Tcl with
  limited access to the machine and master interpreter.

* Obvious Lisp inspiration:
  * Homoiconic through strings
  * Usual FP goodies like map/filter/apply
  * Already mentioned macros
  * Proper prefix arithmetic allowing for * 4 [+ 1 2 3] instead of
    expr {(1 + 2 + 3) * 4} with sane behaviour for more than two (reduce) or
	zero (neutral element) arguments.
  * Multiple more-or-less powerful object systems ([incr Tcl] for C++ style OO,
    XoTcl for CLOS inspired OO or Snit for something Tk oriented).
  * All of that with the same advantage of CL: it does not enforce nor preach a
    particular way of programming, unlike the ML family that comes with the
    "everything is immutable" ball and chain that often gets in the way instead
    of helping (because, big surprise, modifying data is often an essential
    part of efficient and intuitive algorithms while recursing only makes sense
    when manipulating recursively defined data types).
  See https://wiki.tcl-lang.org/page/Functional+Programming for more.

* Biggest inconvenient is the near-death state of the language and community
  (practical consequences: no LSP/SLIME equivalent, bugs accumulating, lack of
  maintainted libraries) as well as some warts that can't be solved easily.
  As someone who knows a bit of CL, the language itself is less powerful
  (especially on the macro side) but the standard library is miles ahead.

Basically, a mix of CL and sh that somehow managed to end up very good and
getting even better with time.


I could continue all day, but you should just try it. Some more talk about it:
* https://wiki.tcl-lang.org/page/What+is+Tcl
* https://wiki.tcl-lang.org/page/Tcl+Articles
* https://colin-macleod.blogspot.com/2020/10/why-im-tcl-ish.html
* https://yosefk.com/blog/i-cant-believe-im-praising-tcl.html
* http://antirez.com/articoli/tclmisunderstood.html

Where to begin:
* man n Tcl (or man 3tcl Tcl on retarded distros like Debian)
* https://wiki.tcl-lang.org/page/TCL+for+beginners
* https://wiki.tcl-lang.org/page/Tcl+Tutorial+Lesson+0
* https://wiki.tcl-lang.org/ for everything, this is where the Tcl community lives
* Rosetta Code for examples/exercises
Replies: >>4024 >>4029
>>4021
Most of these things sound like damningly faint praise, if not outright downsides.
Replies: >>4029
>>4021
Interesting stuff.

>>4024
You're a faggot.
Replies: >>4030
>>4029
Not as much as you. Let's go through a bunch of points.
>* Extremely small - whole syntax/grammar is described in 12 rules in a single man page (Tcl(n)) of 150 lines and there's no reserved keyword.
I can describe Brainfuck on a register receipt. This means nearly nothing.
>* Official man pages! No pydoc or cppreference garbage, here you almost have C degree of exhaustivity.
I would fucking hope the language has documentation, and Python and C++ have it. Is it supposed to be a good thing that the documentation comes in one specific format you like?
>* At least two implementations with jimtcl being a very thorough embedded one.
Two implementations is a low number.
>* Comparable in speed to cpython
This isn't something to brag about, cpython is abominably slow.
>* Cool type system that is superficially "everything is a string" (like sh) but in reality "everything is a tagged union with on-the-fly conversion when needed and a unique string representation". 
Cool, I love implicit conversions. Why think about what type something is anyway?
>* Talking about types, multiprecision arithmetic is transparently handled
This is absolute fucking baseline for a managed language.
>Together with trace, you can write an internal debugger in few lines.
You know what's even better? Having a good debugger out of the box.
>On the subject of performance and simplicity, no need for an actual garbage collector, reference counting is enough because you cannot make circular references.
Reference counting is GC.
>* Safe interpreters let you do very fun things like config files in Tcl with limited access to the machine and master interpreter.
Turing-complete config formats are a terrible idea.
>* Obvious Lisp inspiration:
This one is my favorite, and it's so common too. Why not just use Lisp then? They always go "oooh it has these 20% of Lisp" but never "and here is why we didn't add the other 80%".

Seriously, this is supposed to be singing praises?
Replies: >>4036
>>4030
I'm not a faggot, you are. 
The most important parts are in the first four paragraphs of his post.  
>I can describe Brainfuck on a register receipt. This means nearly nothing.
There's thousands of retarded languages retarded faggots use to solve "code golf" crap in Shekel Exchange, for instance, that can be described in two pages. We are talking about real, general purpose, mature languages. Simplicity can be good. Consider the ISO C++ standard, which is currently 1800+ pages long.  
>Is it supposed to be a good thing that the documentation comes in one specific format you like?
Yes, having official documentation in a good standard format is good. One language I like allows embedded documentation in a simple markup format at the end of code files. That allows us to read, document and maintain stuff easily. The websites cppreference and cplusplus are messes, with "since C++11, removed in C++20" all over (this is related to the previous point).
>Two implementations is a low number.
How about only one, maintained by a foundation sponsored by big companies? He said "at least two" - consider the point about simplicity again.
273849668cf98561c7981cbe60b51ff5afd175006e0ccf5363e2c0049816aac9.jpg
[Hide] (62.9KB, 720x540)
Not sure if this is the right place to ask but I'll start here...
I package other people's native loonix video games as AppImages for portability reasons, and I bundle all dependencies including glibc. However I don't bundle OpenGL / Mesa / video libraries (e.g. libGL.so) that are needed by 3D games as those libraries are system-dependent and the AppImage should use the system ones... This makes sense but it has caused problems with some games; I would package an AppImage and it would run nicely for a few months, then after a system update it would refuse to launch and throw "undefined symbol" / "bad value" errors, so I compile the game again (same exact source code) and package it and it works.
Any idea on why that happens? Any way I can prevent it from happening so I just compile/bundle once?
Replies: >>4052 >>4057
>>4050
Those are ABI incompatibilities, you can't prevent them.

BTW Literally everything in a program and about a program is system dependent, including all the libraries you bundle in.
AppImage is a non solution which makes things even worse.
Programmers need to be taught not to nigger rig build systems instead, but I guess that comes after teaching programmers to program.
Replies: >>4054
>>4052
I see your point... Still, there should be a way to do it. I know it can be done because some emulators use OpenGL and their AppImages keep running at least for me, I just don't know how they do it.
>AppImage is a non solution which makes things even worse.
AppImage is an acceptable solution to a very specific problem, it's not meant to replace traditional package managers. Ideally I wouldn't have to use it because the problems it tries to fix wouldn't exist in the first place.
>>4050
From which library do you see undefined symbol?
Replies: >>4058
>>4057
A couple of *_dri.so libraries, here's the full output:

possible language: typescript, relevance: 12
libGL error: MESA-LOADER: failed to open iris: /usr/lib64/dri/iris_dri.so: undefined symbol: amdgpu_query_video_caps_info (search paths /usr/lib64/dri, suffix _dri)
libGL error: failed to load driver: iris
libGL error: MESA-LOADER: failed to open iris: /usr/lib64/dri/iris_dri.so: undefined symbol: amdgpu_query_video_caps_info (search paths /usr/lib64/dri, suffix _dri)
libGL error: failed to load driver: iris
libGL error: MESA-LOADER: failed to open swrast: /usr/lib64/dri/swrast_dri.so: undefined symbol: amdgpu_query_video_caps_info (search paths /usr/lib64/dri, suffix _dri)
libGL error: failed to load driver: swrast
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  152 (GLX)
  Minor opcode of failed request:  3 (X_GLXCreateContext)
  Value in failed request:  0x0
  Serial number of failed request:  42
  Current serial number in output stream:  43
Replies: >>4063 >>4064
>>4058
I am not sure this is an ABI compatibility issue. The error message says it is trying to find a function for amdgpu in library for "iris" (Intel gpus) and swrast (don't know what it is, but it is not amd gpu). You should make an issue on mesa gitlab if you can still reproduce it.
Replies: >>4065
>>4058
Are you sure you aren't bundling Mesa or anything driver-related?
Replies: >>4065 >>4114
>>4063
I think the error is misleading and it probably is an ABI issue, or else the game wouldn't recompile, no?
>compile game against iris_dri.so
>game works and keeps working
>iris_dri.so gets updated
>game no longer works
>recompile game using the exact same source code against the updated iris_dri.so
>game works
I could just bundle the *_dri.so files (all of them, for all GPUs) inside the AppImage, but that might bring more harm than good, I'm sure there's a better way.

>>4064
I'm fairly sure, the script I'm using blacklists all these files:
>/lib/libGLX.so.0
>/lib/libGL.so.1
>/lib/libGLdispatch.so.0
>/lib/libGLX_mesa.so.0
>any *_dri.so file
Am I missing something?
Replies: >>4066 >>4114
>>4065
When you dynamic link, it will compile as long as the header file has the right functions. So you are not compiling against *.so, you are compiling against *.h.
>I could just bundle the *_dri.so file inside the AppImage
You should ask mesa people directly (or search their gitlab) by making an issue. They would know how to best do this. Let me know how it goes too, I am interested.
You can alternatively try to extract those game emulator appimages (--extract-files) and see if they bundle *_dri.so.
Replies: >>4067 >>4114
>>4066
>you are not compiling against *.so, you are compiling against *.h
Oh...
>ask mesa people directly
Alright, I opened an issue here: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5788 and will post relevant updates ITT as well.
>try to extract those game emulator appimages
Good idea. I just extracted one (duckstation) and it didn't have any _dri.so files, which left me even more dumbfounded as that AppImage was built early this year.
Replies: >>4114
sigma_v-sauce.webm
[Hide] (3.7MB, 1920x1080, 00:35)
What do you call it when someone writes a program with no sense or rhyme to it, globals everywhere for no reason, no organization, and the source is full of weird as fuck constructs like:
language: c
if (!do_thing)
    ;
else
    ...It's like the programming equivalent of the schizo in my video. They just throw code at it until the output is what was expected and it's too cryptic to review and try to find a bug in it, it's like a bad compiler wrote the source.

This is something else, it's not just spaghetti code.
Replies: >>4183 >>4231 >>4232
>>4066
>>4067
I think I found a solution; the blacklist in >>4065 was missing these files:
>lib/libdrm.so.2
>/lib/libdrm_*
So by removing them from the AppImage it works again, >>4064 had the right idea.
I found an "exclude list" provided by one of the AppImage tools which included the files above, along with these:
>lib/libglapi.so.0
>lib/libgbm.so.1
>lib/libEGL.so.1
Thanks for the help anons, I'll keep the Mesa issue open. I also uploaded the fixed AppImage so others can test it on their distros: https://pixeldrain.com/u/7MikYCvG
>>4112
Dare I even ask where this code is from?
Replies: >>4267 >>4412
>>4112
I once wrote something like while((!((2>>1)<0))&&((8>>3)==1)) as a joke.
>>4112
monkeys & typewritters
>>3463
>Nix's package manager
I'd be interested in a completely static linux but Nix is a bad choice for a package manager. I tried it (outside of NixOS) and it was so unbelievably massive, almost a gigabyte of data was spawned just to run a basic graphical program. It also threw its files into a spaghetti structure inside /nix and any given binary cannot run without its wrapper script containing hard-coded paths.
>>4183
Not to be a buzzkill but I could easily see this happening.
>intend to add a feature depending on "do_thing", but then choose not to in MVP
>originally have a print debug statement there, then delete it once everything's done without reorganizing.
>originally have a function return early, but then it's only used in one place so it's moved without revising it.
I feel like a lot of shitty code isn't intentional but more an artifact of hacking shit to work properly together.
>>4183
Some company I applied for. I got to look at their source code. The entire thing was like that.
They asked for "7 years of experience" and they were writing stuff anyone with 6 months of experience and some sense could do better.
Replies: >>4453
>>4412
a lot of people do this, especially when youre building on code you didnt write, its easier to just play around with test code and figure out whats going on during runtime then actually analyzing someone elses code
things you would consider retarded like while(0), &var[0] etc. are just leftovers from talented testers
>>4557
But is the viagra FOSS?
>>4557
Do you have cialis without systemd?
C books
* Read The C programming language, 2nd edition by K&R and/or C Primer Plus, 6th edition by Prata
* After K&R or C Primer Plus, read 21st Century C, 2nd Edition by Klemens
* Also, read Hacking: The Art of Exploitation, 2nd edition by Jon Erickson (it teaches you a lot of different topics)
* The free "Modern C" book: https://gustedt.gitlabpages.inria.fr/modern-c/
* The #c IRC channel's home page: https://www.iso-9899.info/wiki/Main_Page (if you need a IRC client, install Weechat or Irssi or Hexchat)

C++ books
* If you don't know how to program, read "Programming: Principles and Practice Using C++", 2nd edition by Bjarne Stroustrup. (aka PPP2).
* If you know how to program but don't know Cpp, read "C++ Primer", 5th Edition by Stanley B. Lippman; Josée Lajoie; Barbara E. Moo.


General tips and links for C/C++
* Install GCC or Clang. Also, install splint/cppcheck, gdb, valgrind, ltrace, strace and afl. You also need an editor, like Emacs, Neovim or VSCodium. (VSCode is a botnet)
* Do use things like -fsanitize=address https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
* Follow a style guide: https://suckless.org/coding_style/
* Use a reference: https://en.cppreference.com/w/
* The Ten Commandments for C Programmers: https://www.lysator.liu.se/c/ten-commandments.html
* about undefined behavior: https://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html
* Smashing the Stack for Fun and Profit: https://insecure.org/stf/smashstack.html
* What every programmer should know about memory: https://lwn.net/Articles/250967/
* A Guide to Undefined Behavior in C and C++: https://blog.regehr.org/archives/213
* What Every Computer Scientist Should Know About Floating-Point Arithmetic: https://dl.acm.org/doi/10.1145/103162.103163 or https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
* Use include guards: http://www.cs.kent.edu/~nmadi/CS2/Notes/include_guard.html and http://faculty.cs.niu.edu/~mcmahon/CS241/c241man/node90.html 
* If you are looking for a GUI lib, use SDL. FLTK, wxWidgets or QT. (tk is also an option)
* SDL tutorial: https://lazyfoo.net/tutorials/SDL/
* SFML
* https://godbolt.org (compiler explorer)
* Use makefiles: https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/ or https://makefiletutorial.com
* Use the recommended compiler options: -std=c99 (or -std=c++17) -Wall -Wextra -Wformat=2 -Wformat-truncation (perhaps also add -pedantic) (clang also has -Weverything)
* If you build a debug build, add -Og -g -g3 options.
* For security, use -D_FORTIFY_SOURCE=2 and -Wl,-z,now and -fstack-protector-all and -fstack-clash-protection linker/compiler options. (don't use -fstack-check)
* Sometimes changing compiler optimization options/the compiler can unearth bugs in your code.
* Read Programming Pearls, 2nd edition by Jon Bentley
* CERT C Coding Standard: https://wiki.sei.cmu.edu/confluence/display/c/SEI+CERT+C+Coding+Standard
* Agner's optimization manuals: https://agner.org/optimize/
* Programming from the Ground Up Book https://savannah.nongnu.org/projects/pgubook (teches you how a compiler works)
* https://www.cs.cmu.edu/afs/cs/academic/class/15492-f07/www/pthreads.html (pthreads tutorial)
* http://www.csc.villanova.edu/~mdamian/threads/posixthreads.html (another POSIX threads tutorial)
* https://en.wikipedia.org/wiki/Concurrency_pattern
* http://libdill.org (Structured Concurrency for C)
* https://www.invidious-us.kavin.rocks/watch?v=_z-RS0rXg9s&list=PLzLzYGEbdY5lrUYSssHfk5ahwZERojgid&index=1 (a good tutorial series on Parallelism. Bisqwit also has a lot of other stuff)
* https://invidious.snopyta.org/channel/UC-yuWVUplUJZvieEligKBkA (javidx9)
* Advanced Programming in the Unix Environment aka APUE
* TCP/IP illustrated vol. 1

about fork() and friends
* fork() vs. vfork(): https://gist.github.com/nicowilliams/a8a07b0fc75df05f684c23c18d7db234 (p.s. vfork() sucks)
* the A fork() in the road paper from M$ Research: https://www.microsoft.com/en-us/research/uploads/prod/2019/04/fork-hotos19.pdf (I also found this lecture helpful: https://www.youtube.com/watch?v=uRYyj8tcDTE)
* fork() can fail: https://rachelbythebay.com/w/2014/08/19/fork/
* Also: vfork considered dangerous: https://ewontfix.com/7/ (from the author of musl)
* rfork() from Plan9: https://www.freebsd.org/cgi/man.cgi?query=rfork&sektion=2&apropos=0&manpath=FreeBSD+14.0-current (FreeBSD version)
* https://man7.org/linux/man-pages/man3/posix_spawn.3.html (a simpler equivalent for fork+exec)
(what win32 has is different but it sucks, too)
Replies: >>5137 >>5192
How did terry do it? how can one man make his own compiler, language and operating system? Has anyone ported DOOM to TempleOS yet?
Replies: >>5138 >>5140
>>5123
>valgrind
>-fsanitize=address
Incompatible.

>afl
What kind of beginner is going to do fuzz testing.

>ltrace, strace
Pretty pointless to run on your own code.

>link link link link
Having one good resource you strongly recommend is way more valuable than a random dump of shit you haven't read.

Overall 5/larp
Replies: >>5177
>>5135
It took him like 7-8 years. And Terry had experience from the time he was working at Ticketmaster (they wrote a fucking compiler).

> Has anyone ported DOOM to TempleOS yet?
No, as far as I know.
>>5135
Writing a compiler is aproachable if you don't do any register allocation, control/data flow analysis, etc.
There are baby steps for developing a compiler, you can skip over the front end by using something like symbolic expressions and let binutils, llvm, jit libraries handle the backend.
SICP and "Algorithms + Data Structures = Programs" have tiny compilers that you can understand.
The dragon book isn't a good intro.

An OS on the other hand doesn't really have baby steps.
There are legacy interfaces (PIC, PIT, VGA) that make it slightly more simple but you will still spend months just setting up some page tables, memory management and interrupt routines that do nothing but show a smiling ASCII character and beep when you press a key.

You can find millions of interesting programming languages made by individuals, but 99% of all DIY operating systems are unix clones "inspired" by minix, bsd, et. al.
>writing a compiler
babby shit
write a dynamic linker fag
Replies: >>5177
sips.jpg
[Hide] (14KB, 179x200)
>What are you working on?
The latest bump reminds me I never answered this.

I wrote a very trivial but nonetheless useful program many months ago: I was unsatisfied with all the programs I tried that serve the same purpose. The initial version was 20-50 lines of code and it does almost the same thing the current version does, I never commited it to git, so I don't have it. Keep in mind that the program I see mine as a replacement for is in the 900LoC range, it has way more features, but I find them useless for any sensible use case.

I did, however, want to make the most perfect program possible. I'm a fan of portability and I spent a lot of time studying proper programming practice and techniques.
The original program, which mine is a reimagination (not reimplementation) of, has no tests, uses deprecated C functions like strcpy(), only runs on Linux (you will find packages for other OSes but it's because they patched the program), uses the old man format for its manual, has very complicated and obtuse logic, doesn't check the return values of the printf() calls that produce its output, the build is nigger rigged to the point it has a sed script for patching the build definitions to specify the install location, it just sucks. And really, those printf()s could have been fputs() calls (read the source of its implementations, fputs() is a shorter code path), the imperfection of that already annoys me greatly.

So I took my 50 line program and I made it into a real product, in the good sense. It was written against the OpenBSD libc. It pledge()s itself, it uses arc4random() for random numbers, and a later version added a flag that is parsed with strtonum(), that's the extent of the program's ties to the OpenBSD libc. The build is LTO'd by default, there is no reason to write code that breaks under LTO and there is no reason not to use it always. I do not ever call malloc() (the program is designed to be simple enough to not need it, not to artificially avoid it), I wrote the manual using mandoc(7); I also wrote simple, sensible, and portable build definitions.

Then I went absolutely nuts: I added a few tests, and I ported it to every single platform I could get my hands on. I ported the program to Haiku, Windows, all the BSDs, all the Linux libcs (except uclibc-ng and picolibc because I couldn't get them to work), Mac OS, Android (bionic libc Linux), they are around 15 in total. I automated building and testing on every single platform I consider my program ported to with GitHub Actions (Microsoft already built my program over 10000 times BTW), I automated releases, I wrote a Windows installer, I worked hard until the build instructions were the exact same for every single platform (except for the additional installer step on Windows).

I also added support for every single pledge() equivalent I could find: I got Mac OS' sandbox_init(), I got FreeBSD's capsicum(), and I have setrlimit() for any other POSIX-like platform. I feature test for their presence and this is the only conditional compilation in the whole program, there isn't a single #ifdef, my build definitions plug in the best implementation or a null one depending on availability and not on platform. Instead of rewriting my program in something closer to Standard C, I just ported the OpenBSD libc functions I needed to every single platform; that includes Windows, I don't need MinGW's getopt() or Cygwin but I can build with them-that's why I say I went nuts, I indiscriminately added support for every single platform I could get my hands on. Even the MSVC build just works with the same build instructions as Haiku or Linux.

I'm proud of my extreme level of portability, how my program works anywhere while respecting every platform's peculiarities and taking advantage of their good features; and I'm proud that I didn't stoop down to using deprecated functions and general poor programming practice to achieve it. There is absolutely 0 duplicate code where it's not needed, and it's only needed in the pledge() case. The program's core logic ballooned to 300LoC when I added error checking to its output functions, a single option I deemed useful, and all the pledge() equivalents.
I'm also expanding the compat library because I plan to use it on my next project and shill it on some project I contribute to. It has even already made its way into 1 repository.

BTW, absolutely make your programs portable, but do it properly-you will find bugs.
>>5153
Holy fucking shit anon you are autistic. Good job. How long did it take?
Replies: >>5155
>>5154
3 months.

Most of that is blamed on Windows, it was the most painful platform to deal with by far. Windows sucks so much that it shed a light on me: a Windows programmer with 20 years of experience is a novice because he spent 19 years and 6 months struggling with Windows and 6 months actually programming, just like I spent ~2 months working on the Windows version of my program, most of which weren't spent actually programming, they were spent fighting against Windows.
Replies: >>5156
>>5155
By the amount of time you spent on this, there should have been a compat library already. Is that only for pledge and strtonum()?
Replies: >>5157
>>5156
There are many libraries of this kind, but they all seem abandoned or limited. Haiku has an extremely incomplete one and you have to read the source code to figure out how to use it. FreeBSD has one (the BSDs aren't 100% compatible) but their libc already has all the functions I need anyway. Cygwin has a lot of BSD functions in its libc, but it just happens to not have strtonum(). dietlibc has a BSD compat library of middling completeness, but it still didn't have all the the functions I use. MinGW has a few functions that are easy to implement on Windows without simulating an entire POSIX system like getopt(), but that's not nearly enough. There's libbsd for Linux and Linux only, it has everything I need, I support building exclusively with it. For every single system that has a BSD library, my compat library will link in that library, and won't include in itself the symbols the system's library provides. If the system has all the functions (as FreeBSD and libbsd do), my compat library isn't even built.
Also, some OpenBSD projects like OpenSSH and LibreSSL are portable, those have their own compat libraries, which is what inspired me to make my own.

It's impossible to port pledge(), it's not part of my compat library, I just wrote a sandbox() function and implemented it for every sandbox framework, then the build system pulls in the right source file. The program calls sandbox() at the start. This is an imitation of what OpenSSH does, I learned it from reading its source code.

The compat library isn't only for the few functions this program needs, I added a lot of functions that my project doesn't use but that others use and I wrote, copied, or reimplemented tests for almost all of them. I also added the functions that one of the projects I contribute to needs. Ideally, I would figure out a way to replace Gentoo's libbsd package with my library, build everything that depends on libbsd, and fix the build failures by adding functions to my library, but I haven't gotten around to it.

Also, other libraries have lots of caveats. libbsd doesn't even run on every Linux system.

Oh, and I went even further, I ported my tests to every single platform too. The tests I reimplemented were reimplemented so they can run on every platform. My test for getopt() also builds and runs on platforms that have a getopt() for instance. My getopt() test tests for BSD behavior, I can see it fail on platforms that are not BSD-like, but I haven't done anything about it because I don't use features specific to BSD getopt(). By doing this, I already found 2 bugs in 2 different libcs, and in the same function. Most libcs don't have all that many tests, so I'm probably the first one running a test suite against them.
>>5137
Definitely a larp, but that's how most "helpful copypastas" are on IBs generally... I'm considering writing my own (short) copypasta once I go through enough resources so I can recommend only the good ones.

>>5151
>dynamic linker
Kill yourself.

>>5153
Nice work anon, it's refreshing to see developers care about portability.
>deprecated C functions like strcpy()
I'm currently going through K&R (CPL ANSI C edition) and it consistently uses strcpy... What am to do now?
>Mac OS
Emulated or the real thing? I've been curious about cross-compiling for macintoshes as someone who never used the damn thing.
>>5177
The damn thing sucks so much it's unreal. A VM if you manage to do it would be the best, otherwise ebay.
Replies: >>5180
>>5177
>I'm currently going through K&R (CPL ANSI C edition) and it consistently uses strcpy... What am to do now?
The problem with K&R is that it doesn't teach you the new stuff (or tell you what is the old bad stuff). Which is why I read C Primer Plus in addition to K&R. Anyway, you need to use something like strncpy (that checks the bounds)
Replies: >>5180
>>5178
I figured... Into the trash it goes.

>>5179
>The problem with K&R is that it doesn't teach you the new stuff
Goddammit. I already had my gripes with K&R so this is just great.
>read C Primer Plus in addition to K&R
Alright, thanks.
>you need to use something like strncpy (that checks the bounds)
That sounds like a good solution, because strncpy is already part of ANSI C which is the most portable.
Replies: >>5181 >>5184
>>5180
>That sounds like a good solution, because strncpy is already part of ANSI C which is the most portable.
This reminds me, when the times comes and you need more advanced stuff, try to stick to things defined by the POSIX (so your programs will be portable to other POSIX systems, like *BSD). There are things that are specific to Linux like clone(2) or OpenBSD's strlcpy(3). Get a copy of Advanced Programming in the Unix Environment.
Replies: >>5186 >>5210
rinkosweat.png
[Hide] (40.9KB, 262x629)
>>5177
>I'm currently going through K&R (CPL ANSI C edition) and it consistently uses strcpy... What am to do now?
Don't worry about it and finish the book, unfortunately the C committee conflates backwards compatibility with backwardness compatibility which creates these sorts of situations where new C programmers need to waste time being told not to use a certain part of the language decades after that part of the language should have been removed, but at least here it's a small hurdle.

K&R C is an excellent book, not because of its treatment of the stdlib (which is actually poor), but because it teaches you proper programming philosophy, practice, and techniques in a very easy to understand manner; it also actually helps you understand the C language and all of its features. You don't want to be like those C programmers who don't understand pointers or have never heard of the bitwise operators, K&R C will make sure you aren't one of them.
Additionally, the parts of K&R C that you will have to be told not to follow are very minimal, further learning the C language is almost entirely about adding to what K&R taught you. The newer books might tell you about newer things you should use like the standard function snprintf(), but they will likely have more things to unlearn than K&R C did, and they won't cover extremely important material as well as K&R C does. K&R C is easily one of the best introductions to a field ever written, it's a must read.

After K&R C, you can read this paper: https://www.openbsd.org/papers/strlcpy-paper.pdf
It has a very elaborate explanation of why strlcpy() and its sister function strlcat() are better than strcpy(), strcat(), strncpy(), and strncat(). Both are trivial to implement (and good exercises for beginners) in pure Standard C and there are many preexisting libre implementations in many libcs and compatibility libraries you can depend on or copypaste, so there's no reason to use the stdlib over them. Actually, strncpy() and strncat() make sense for fixed-width fields, but that's not what the great majority of your C string operations will be dealing with.

Additionally, I recommend C Programming: A Modern Approach for learning the parts K&R C doesn't cover.

>>Mac OS
>Emulated or the real thing? I've been curious about cross-compiling for macintoshes as someone who never used the damn thing.
Emulated. The BSDs are all very similar and the MacOS libc is a lot like the FreeBSD it's derived from. Apple seems to apparently arbitrarily refuse to add some functions FreeBSD adds, but it's still almost exactly like FreeBSD, it was one of the easier platforms to port my program to. 

>>5180
>That sounds like a good solution, because strncpy is already part of ANSI C which is the most portable.
That's not a good way of doing portability. You should always use the best practices possible, then when you want to port your program, you should bring your good practices to the backwards platform instead of bringing the platform's backwards practices to your program. strncpy() is not a suitable function for "copy this string to that buffer" because it unnecessarily zeroes the buffer and doesn't guarantee null termination, it's easy to do better than that. strncpy() makes sense for fixed-width fields that you're going to commit to storage and you don't want to write garbage or you want to make sure you don't leave spare 1-bits in ROM which can still be written to (ROM is really Write-Once Memory).

Consider this paper: https://www.openbsd.org/papers/portability.pdf
OpenSSH is an extremely portable program. My program is trivial, it's always easy to do anything with trivial programs, but OpenSSH is not at all a trivial program and it's one of the most portable programs out there, and that pdf tells you about some of their philosophy for doing portability and their techniques for doing so. You can definitely make use of strlcpy() and simultaneously have a portable program that doesn't have its core logic polluted by a million #ifdefs making the whole thing unintelligible, the OpenSSH guys have achieved it, you just have to do the same thing they're doing.
Replies: >>5193 >>5210
>>5181
> stick to things defined by the POSIX (so your programs will be portable to other POSIX systems, like *BSD).
By this logic you should just write java. The whole point of C is to squeeze the most out of your chosen platform.
Replies: >>5192
>>5177
>>5123
I would reformat and clean up the paste:
C books
* Read The C programming language, 2nd edition by K&R and/or C Primer Plus, 6th edition by Prata. (Although K&R is a great book, it doesn't teach you what is considered harmful now!)
* The #c IRC channel's home page: https://www.iso-9899.info/wiki/Main_Page (contains a lot of links and tips. there is a book list, too)
* (cont.) If you need a IRC client, install Weechat or Irssi or Hexchat (GUI).

C++ books
* If you don't know how to program, read "Programming: Principles and Practice Using C++", 2nd edition by Bjarne Stroustrup. (aka PPP2).
* If you know how to program but don't know C Plus Plus, read "C++ Primer", 5th Edition by Stanley B. Lippman; Josée Lajoie; Barbara E. Moo. the formatting freaks out if you use 4 pluses on the same line


General tips and links for C/C++
Compilers and tools
* Install GCC or Clang. You also need an editor, like Emacs, Neovim or VSCodium. (VSCode is a botnet)
* Do use things like -fsanitize=address https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html  or Valgrind.
* Use include guards: http://www.cs.kent.edu/~nmadi/CS2/Notes/include_guard.html and http://faculty.cs.niu.edu/~mcmahon/CS241/c241man/node90.html 
* Compiler explorer https://godbolt.org (Sometimes changing compiler optimization options or the compiler can unearth bugs in your code.)
* Use makefiles: https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/ or https://makefiletutorial.com (if make is not enough for you, use Cmake)
* Use the recommended compiler options: -std=c99 (or -std=c++17) -Wall -Wextra -Wformat=2 -Wformat-truncation (perhaps also add -pedantic) (clang also has -Weverything)
* If you build a debug build, add -Og -g -g3 options.
* For security, use [-fcf-protection] -fstack-protector-all and -fstack-clash-protection compiler options. Don't use -fstack-check
* (cont.) More info: https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc


Additional recommended reading
* Follow a style guide: https://suckless.org/coding_style/
* Use a reference: https://en.cppreference.com/w/
* CERT secure C Coding Standard: https://wiki.sei.cmu.edu/confluence/display/c/SEI+CERT+C+Coding+Standard


Must reads
* Advanced Programming in the Unix Environment aka APUE (great reference for POSIX stuff.)
* About undefined behavior: https://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html (a must read for every C/C++ programmer)
* Smashing the Stack for Fun and Profit: https://insecure.org/stf/smashstack.html (a must read for every C programmer)
* Hacking: The Art of Exploitation, 2nd edition by Jon Erickson (it teaches you a lot of different topics, such as basics of crypto, sockets programming and stack overflows)


Other
* The Ten Commandments for C Programmers: https://www.lysator.liu.se/c/ten-commandments.html
* What every programmer should know about memory: https://lwn.net/Articles/250967/
* Read Programming Pearls, 2nd edition by Jon Bentley (teches you how to approach a problem)
* 21st Century C, 2nd Edition by Klemens (teaches you about various tools and libraries. it also covers some more advanced features of C)
* TCP/IP illustrated vol. 1 (a good reference)
* Effective Modern C++ (and other books by Scott Meyers)

Asm
* Agner's optimization manuals: https://agner.org/optimize/
* Programming from the Ground Up Book https://savannah.nongnu.org/projects/pgubook (teaches you how a compiler works)
* Professional Assembly Language by Richard Blum
* The Art of Assembly Language Programming by Randall Hyde: https://www.plantation-productions.com/Webster/ & https://www.randallhyde.com  (the 2nd edition uses HLA, but the first DOS edition uses regular 16-bit x86 asm. There is also now The Art of 64-Bit Assembly.)


>>5186
>The whole point of C is to squeeze the most out of your chosen platform.
Yes, but another point of C is that it is extremely portable. Of course, you can use the C preprocessor macros to do conditional compilation (add #ifdef clause for each platform and use #else to make it use POSIX or something): https://wiki.osdev.org/C_preprocessor & https://tldp.org/LDP/lpg/node148.html
Replies: >>5194 >>5210
>>5184
>You don't want to be like those C programmers who don't understand pointers or have never heard of the bitwise operators, K&R C will make sure you aren't one of them.
Thank you for explaining why K&R C is overrated crap. Yes, it's a good beginner tutorial, that's it. It wont teach you basic stuff required for your program not to be a hacker playground, like signal-safety(7).
>>5192
>Yes, but another point of C is that it is extremely portable.
Portable across CPU architectures relative to assembly. That's not the same thing as being 'cross platform'.

If you want glass over platform specific details and just have the same source run on multiple platforms then why are you even using C? You're telling people to use a fork to eat soup.
I heard learning C before learning C++ will make old practices hard to unlearn.

I hate how I can't goto over variable definitions in C or C++, this is surprisingly annoying. There is no technical reasons why this can't be done if you don't use constructors and destructors.
Replies: >>5200 >>5209
>>5198
Just don't learn C++ then, afterall it's a terrible programming language. Why waste your time making yourself a worse programmer?
You mean people hire C programmers over C programmers anywhere? There is probably 1 C programmer required over 10000 C ones.

I wouldn't call it a terrible language. Bloated yes, but you don't have to use most of C++ features, it's still an improvement over just C.
Replies: >>5202 >>5210 >>5229
0ca653be057afe1bd301710b27931cc8b9aeb192633c84a5169d778a4f4ba8cb.jpg
[Hide] (36.7KB, 348x342)
>>5201
>You mean people hire C programmers over C programmers anywhere? There is probably 1 C programmer required over 10000 C ones.
You mean people hire C programmers over Cplusplus programmers anywhere? There is probably 1 C programmer required over 10000 Cplusplus ones. Fucking markup.
Replies: >>5207
>>5153
You can't write all that and then not post any code, dude, what the fuck. I recently came to hate portability through source code when there is already binary portability through wine, but I'm still curious to see what you made.
Replies: >>5205
>>5204
/tech/ - only tease
>>5203
boost and other libraries also makes a convincing argument.
I am working on a web frontent on C. I wanted to use C but there is no sufficient webshit library in C. But there are several framework on C, which makes it possible. Why not python? I hate the language and its version changes too quickly. C++ standard stays pretty much still for old programs. I could have opted for rolling my own database abstraction and cgi, but that'd take too much time.
Replies: >>5208 >>5210 >>5219
>>5207
>frontend on Cpp. I wanted ... several framework on Cpp,
Fuck markup, what is the escape sequence?
Replies: >>5209
>>5198
>I heard learning C before learning C++ will make old practices hard to unlearn.
That's nonsense. I think it makes sense to learn C before learning C++ because C is the simpler language.
Because C and C++ are separate but closely related languages.
And you absolutely need to know pointers, C strings, malloc() and extern "C" if you are a C++ programmer. 
Especially in embedded systems and older C++ code, you need to also know C.
> https://isocpp.org/wiki/faq/mixing-c-and-cpp

>>5208
>what is the escape sequence?
A new line.  This is C++-free zone : ^) 
>>5181
>try to stick to things defined by the POSIX
That's what I intend to do, although I wish to also target Windows. Hopefully mingw and friends save my ass.
>Advanced Programming in the Unix Environment
Thanks.

>>5184
>a certain part of the language decades after that part of the language should have been removed
I get the frustration, but I totally commend the committee for retaining 100% backward compatibility for better or worse. It's nice to pull a C program from decades ago and have it compile nicely.
>K&R C is an excellent book [...] because it teaches you proper programming philosophy, practice, and techniques in a very easy to understand manner
Completely agreed. I still have my gripes with it though... Might write a greentext for that later.
>the parts of K&R C that you will have to be told not to follow are very minimal
Which parts are those? If they're listed somewhere I'd appreciate a link so I can avoid them entirely.
>strlcpy paper
Done, I'll see about implementing it soon.
>C Programming: A Modern Approach
Thanks.
>you should bring your good practices to the backwards platform instead of bringing the platform's backwards practices to your program
>portability paper
Noted. I don't understand some of the things mentioned so I'll probably revisit this after I'm done with K&R.

>>5192
This is still way too long but I guess a little better than before. I don't see why ASM is included in a copypasta for beginners, as well as the IDE/editor autism, among other things.

>>5201
>You mean people hire C programmers over C programmers anywhere? There is probably 1 C programmer required over 10000 C ones.
Fixed.

>>5207
C isn't a magic bullet, and using it for the web makes little sense when there are better suited languages for that... I like the simplicity of Python however the rapid version changes are definitely a huge PITA, also the lack of a concrete method to bundle interpreter+source for end users puts me off.
Replies: >>5213 >>5222
>>5210
> I don't see why ASM is included in a copypasta for beginners, as well as the IDE/editor autism, among other things.
Asm isn't actually hard, but making something except little toys is hard to do in Asm. Perhaps Asm belongs in a different paste. The reason why I included it is that some claim that C teaches you how a computer works, while in reality C teaches you how UNIX works (UNIX and C evolved toughener, after all). I think listing known good editors is a good idea, though. Since you can't do much if you don't have an editor. I think that nano just isn't good enough. Years ago, I tried to rice it as well as I could. I enabled syntax highlighting and the support for editing multiple files But it wasn't good enough. Also, some beginners use joe (probably because a youtuber called "Bisqwit" uses it), however, there is no reason to use joe, unless you are used to Borland Turbo C/WordStar keybindings.
Replies: >>5215
Posted the K&R greentext here >>5214

>>5213
>perhaps Asm belongs in a different paste
Agreed. I think it's enough to have C and C++ in a beginner's paste.
>I think listing known good editors is a good idea
<vim
<good editor for beginners
Anon...
I personally just use any basic (graphical) notepad-like program with syntax highlighting, but if I were to recommend an editor for beginners I'd say VSCodium, Sublime, or KDevelop. Also CodeBlocks is worth mentioning so beginners can focus on code rather than Makefiles.
Replies: >>5218
Vim has a tutorial that takes 30 minutes and teaches you the basics. Those basics alone make it more powerful than Nano, Notepad++, and other less featureful text editors.
I've spent longer than that figuring out how to call a function on Windows.
>>5215
It is a bad idea to get new programmer to use ides. They may not understand what it is doing underneath, but that is important. Using a plain text editor help them understand what source code files are and what is compilation. Vim and Emacs are also very good editors that programmers should know at least the basics of one of them. If the person learning it is on windows, the first step is getting a sensible development environment (like installing linux).
>>5207
I think I actually wrote a shitty webserver in C once. Don't remember in what folder did I put it though.
Replies: >>5222
>>5210
>>5219
I am using a library that abstracts away the web server, some http stuff and javashit. Cpp is comfortable enough for web development with this lib. You probably know what I am talking about, but I can't really talk about it.
If anybody is interested to see jschan development streamed, download lokinet https://lokinet.org/ then visit http://stream.loki/
 mpv chads rtmp://stream.loki/live/tom 
Will be live mornings eastern, when I feel like it.
>>5201
>You mean people hire C programmers over C++ programmers anywhere?
>There is probably 1 C programmer required over 10000 C++ ones.
Have you actually looked at job postings? Or just pulling shit out of your ass?
Replies: >>5233
>>5229
Don't know about him, my area is 70% web shit, 20% C++, 10% embedded (c). Don't see C much outside of that.
csgrad.png
[Hide] (87KB, 2088x2080)
https://hacks.mozilla.org/2021/12/webassembly-and-back-again-fine-grained-sa
ndboxing-in-firefox-95/

Mozzarella's idea of security: Compile C into WASM -> compile WASM into C -> compile C into machine code.
Done. That's security.
Replies: >>5285
>>5283
At this point even Java is a better choice than a fucking browser.
This reminds me about the native C++ webrtc implementation is a part of chromium. Some chinks managed to build it independently. Still there is zero documentation on how to use it in your program. Why should a p2p communication protocol and video chat library be part of a http renderer?
Replies: >>5286
>>5285
*html
octaPNG.png
[Hide] (9.4KB, 512x512)
a6caaca5945c4182ebd3c50e67e23cfa02304283c6c9537f02e5b2cf063f4960.png
[Hide] (293KB, 500x500)
Announcing octaPNG
The past few weeks or so I've been working on a tool to convert arbitrary files into PNGs and back, and today I released the first version. This tool is called octaPNG and it was made mostly for abuse on imageboards and other online forums where only images may be uploaded.
octaPNG was written in C and depends only on libpng and zlib. There are compiled binaries available for Windows and Linux, CLI-only at the moment but a GUI version is Coming Soon™

https://psychicdebugging.com/gillian885/octaPNG
>>5646
$ git clone https://psychicdebugging.com/gillian885/octaPNG.git
Cloning into 'octaPNG'...
fatal: unable to access 'https://psychicdebugging.com/gillian885/octaPNG.git/': SSL certificate problem: unable to get local issuer certificate
On OpenBSD 7.1
Replies: >>5649
>>5648
Try this link for now:
https://psychicdebugging.com/gillian885/octaPNG/archive/master.tar.gz
Replies: >>5657
>>5646
Are you selfhosting that gitea instance?
Replies: >>5664
>>5646
Expect a fish going nuclear.
>>>/v/126027
>>>/v/126029
Replies: >>5654
dansen-1.mp4
[Hide] (545.5KB, 720x720, 00:24)
>>5646
This is really cool, but from my perspective it has massive potential for abuse. If I'm understanding this right any archive could be converted to a png that is the same filesize, correct? Given how simple file hashes are to get around, can you think of ANY way for these png archives to be filtered or at least audited quickly? Or am I going to have to get familiar with pedo-level opsec just to fairly moderate them? I don't want to deny anons utility but I also don't have any friends working at alphabet agencies, prease understandu.

>>5653
This sort of thing has been possible for a while now, trying to stop it outright is a fool's errand for literally any admin/moderator. The only real countermeasure I can think of save for deleting any clown vomit on sight would be compressing image files to  try and corrupt the encoded archive but that would be super gay.
Replies: >>5655 >>5663 >>5664
>>5654
Since it's a png you could run it through optipng for lossless compression. 
It would change the file though, and fuck with the hash for external uses (e.g. hydrus, md5 search).
Replies: >>5656
>>5655
if something like hydrus doesn't use the decoded image's hash that's a bug
Replies: >>5658
>>5649
$ ftp https://psychicdebugging.com/gillian885/octaPNG/archive/master.tar.gz
Trying 176.9.10.37...
TLS handshake failure: certificate verification failed: unable to get local issuer certificate
I can download it by telling ftp and git to not verify certificates, but that should probably be fixed.
Replies: >>5664
1.png
[Hide] (2.2KB, 703x526)
2.png
[Hide] (190B, 703x526)
>>5656
If you change a file it becomes a different file. That isn't a bug.
Replies: >>5659
>>5658
yes, and Hydrus and the like should decode the images before hashing them
Replies: >>5660
>>5659
None of those images have encoded files, they're the exact same except one has been compressed.
>>5646
I fixed the build on OpenBSD, my vim setup also ate a load of trailing whitespace so the patch is larger than it should be.
From 713a6b4b1ca0d952333b95ab2b91d2d10de417d1 Mon Sep 17 00:00:00 2001
From: Anonymous <[email protected]>
Date: Sat, 21 May 2022 04:02:14 +0000
Subject: [PATCH] Port to OpenBSD

Adds a pkg-config dependency and probably works on the other BSDs too.
---
 INSTALL.md   | 37 ++++++++++++++++++++-----------------
 src/Makefile |  4 ++--
 2 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/INSTALL.md b/INSTALL.md
index fc8ca31..9b1c911 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -11,13 +11,13 @@ octaPNG is written to be as portable as possible so it may compile on any system

 ## Compiling under Linux

-1. Install `gcc`, `make`, and the development libraries for `libpng` and `zlib` from your package manager. For example on Ubuntu you can install them using this command:
+1. Install `gcc`, `make`, `pkg-config`, and the development libraries for `libpng` and `zlib` from your package manager. For example on Ubuntu you can install them using this command:

     ```
-    sudo apt install build-essential libpng-dev zlib1g-dev
-    ```
+    sudo apt install build-essential pkg-config libpng-dev zlib1g-dev
+    ```
 1. Open a terminal window in the octaPNG source directory (e.g. `octapng-master` ).
-1. Run
+1. Run

     ```
     make
@@ -29,11 +29,11 @@ These steps are for compiling under a supported version of Windows with internet

 1. Install [MSYS2](https://www.msys2.org/). You should now have the directory `C:\msys64`
 1. Run the MSYS2 shell at `C:\msys64\msys2_shell.bat` and a terminal window will open.
-1. Run
+1. Run

     ```
     pacman -Syuu
-    ```
+    ```
     to install any available MSYS2 updates. Repeat this step until there are no more updates.
 1. Run

@@ -42,8 +42,9 @@ These steps are for compiling under a supported version of Windows with internet
     mingw64/mingw-w64-x86_64-gcc \
     mingw64/mingw-w64-x86_64-make \
     mingw64/mingw-w64-x86_64-libpng \
-    mingw64/mingw-w64-x86_64-zlib
-    ```
+    mingw64/mingw-w64-x86_64-zlib \
+    mingw64/mingw-w64-x86_64-pkg-config
+    ```
     to install all dependencies.
 1. Place the octaPNG source directory into `C:\msys64\home\USERNAME` where `USERNAME` is your Windows user name. You should now have the directory `C:\msys64\home\USERNAME\octapng-master` or similar.
 1. Close the MSYS2 shell, run the MinGW shell at `C:\msys64\mingw64.exe` or `C:\msys64\mingw64_shell.bat` and a terminal window will open.
@@ -56,15 +57,16 @@ These steps are for compiling under a supported version of Windows with internet

 -----

-For 32-bit systems your MSYS2 directory will be `C:\msys32` which contains `mingw32.exe` or `mingw32_shell.bat`
-The command to install all dependencies will be
+For 32-bit systems your MSYS2 directory will be `C:\msys32` which contains `mingw32.exe` or `mingw32_shell.bat`
+The command to install all dependencies will be

 ```
 pacman -S \
 mingw32/mingw-w64-i686-gcc \
 mingw32/mingw-w64-i686-make \
 mingw32/mingw-w64-i686-libpng \
-mingw32/mingw-w64-i686-zlib
+mingw32/mingw-w64-i686-zlib \
+mingw32/mingw-w64-i686-pkg-config
 ```

 ## Compiling under Windows (Offline)
@@ -76,21 +78,21 @@ These steps are for compiling under any Windows version without internet access,
 1. Extract the MinGW-w64 archive into `C:\msys64` . You should now have the directory `C:\msys64\mingw64`
 1. Place the octaPNG source directory, the ZSTD tool renamed as `zstd.exe`, and the libpng and zlib archives into `C:\msys64\home\USERNAME` where `USERNAME` is your Windows user name. You should now have the directory `C:\msys64\home\USERNAME\octapng-master` or similar.
 1. Run the MSYS2 shell at `C:\msys64\msys2_shell.bat` and a terminal window will open.
-1. Run
+1. Run

     ```
     ./zstd -d --rm *.zst
-    ```
+    ```
     to extract all ZSTD archives.
-1. Run
+1. Run

     ```
     for f in *.tar*; do bsdtar -xvf "$f"; done
-    ```
-    and you'll find the directory `C:\msys64\home\USERNAME\mingw64` is created.
+    ```
+    and you'll find the directory `C:\msys64\home\USERNAME\mingw64` is created.
 1. Merge this directory with the one inside `C:\msys64`
 1. Close the MSYS2 shell, run the MinGW shell at `C:\msys64\mingw64.exe` or `C:\msys64\mingw64_shell.bat` and a terminal window will open.
-1. Run
+1. Run

     ```
     cd octapng-master
@@ -107,6 +109,7 @@ Any system containing...

 * A C compiler compatible with GCC flags
 * A Make tool compatible with GNU Makefiles
+* pkg-config
 * The needed development libraries

 should allow compiling the octaPNG source without issue. You might need to edit the `Makefile` inside the root directory or make your own `.mak` file for your compiler and Make tool of choice.
diff --git a/src/Makefile b/src/Makefile
index a21213d..bfa6a89 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
-CFLAGS  = -W -Wall -Wconversion -Wshadow -Wcast-qual -Wwrite-strings
-LDFLAGS = -lpng -lz -lm -ansi -pedantic -s -static -O1
+CFLAGS  = `pkg-config --cflags libpng zlib` -W -Wall -Wconversion -Wshadow -Wcast-qual -Wwrite-strings
+LDFLAGS = `pkg-config --libs libpng zlib` -lm -ansi -pedantic -s -static -O1

 all: ../$(EXENAME)

--
2.35.1


Other than that, I can see from a glance at the source code that:
- You should probably use getopt() instead of that ad hoc command line argument parser pasted from elsewhere.
- You're using floats to deal with exact numbers (square image height/width, filesize). Don't do that. Don't use floats in general.
- Recursive Make Considered Harmful https://accu.org/journals/overload/14/71/miller_2004/
- There's nothing about installing and uninstalling the program in your Makefile. I recommend reading suckless st's Makefile https://st.suckless.org/ for guidance and following GNU's Makefile Conventions https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html when dealing with Make. But what I truly recommend is using Meson as the build system instead. Make forces you to do a lot more legwork and studying to get simple tasks done and in the end produces lower quality build definitions that are less portable anyway. You can learn Meson in its entirety in less time than it takes to figure out a small portion of the good practices that have been developed over the years to make Make suck less and which Meson doesn't need.
- You should break lines in your Markdown like everyone does with source code. A Markdown converter will join them for you when it renders to HTML or whatever.
- You could write a man page. That's more or less obligatory for any Unix program.
- You should probably try writing a package and sending it to a distro to see the kinds of things any repository would want to change in your program before accepting it. For instance, you mandate static linking, your program would be rejected by any OS I know for that. If your project had weight, i.e. if it was famous like say Firefox, they'd try to patch it out. You require -O1, most Linux distros have a standard set of optimizer flags they use and they'd either reject your program or patch that out, though somes OSes don't care and don't touch optimization flags. Loosely following GNU's Makefile Conventions is also obligatory for Make projects.
- streq in ioe.c: There's a bug: the argument to tolower() isn't cast to unsigned char. Additionally, there's a POSIX function called strcasecmp() that does the same thing. Don't worry about the fact that it doesn't exist on Windows because it's trivially implemented in Standard C, you should only worry about the portability of extensions that can't be implemented portably (fmemopen() for instance). In this particular case, Microsoft has a stricmp() that is an exact clone of strcasecmp().
Replies: >>5664 >>5666 >>5669
>>5654
Not him, but your question
>can you think of ANY way for these png archives to be filtered
The problem is not storing data in PNG, it will take some processing power to detect steganography. But you only need to do this for popular steganography formats.
You can't compare the hash of compressed files easily because they are different files. It is the same problem of getting around file hashs. What is your solution to auditing those? You can have your software decompress them automatically and do whatever you normally do with pictures.
Word of advice, you can stop anons from using most of these by re-encoding any media your sever come across, it will be lossy if you are going down this path. But you can't stop everything, there are many more ways to store data in images that will be hard to process automatically. Just any new scheme will have gone unnoticed, maybe you already have cp on your desktop wallpaper it's just saved in a format you don't know.
It is unrealistic to audit this without spending processing power, would it be better to let it slide and argue you have no way to know there are cp in those pictures and it may as well be random (plausible deniability)?
Of course you need to kill threads that makes it obvious (take a pizza leave a pizza threads), but catching the last few percents takes way more effort than the others.
Replies: >>5664
>>5651
>>5657
I'm not hosting this gitea instance so any problems will have to be reported to the site admin(s).

>>5654
>If I'm understanding this right any archive could be converted to a png that is the same filesize, correct?
Yes. See the examples here: https://psychicdebugging.com/gillian885/octaPNG/src/commit/ecc36e943b0bd1b733e58a41964910a43eacc5c3/Examples.md
>Given how simple file hashes are to get around, can you think of ANY way for these png archives to be filtered or at least audited quickly?
The first 3 pixels of any opng, if read as bytes, are like a file header:
_______________________________________
| Pixel | Byte  | Description          |
|¯¯¯¯¯¯¯|¯¯¯¯¯¯¯|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
| 0     | 0     | oPNG version.        |
|       |_______|______________________|
|       | 1     |                      |
|_______| 2     | Binary data size in  |
|       | 3     | bytes, big endian    |
| 1     | 4     | order.               |
|       |_______|______________________|
|_______| 5     |                      |
|       | 6     | CRC32 sum of the     |
| 2     | 7     | binary data, big     |
|       | 8     | endian order.        |
________|_______|______________________|
You can implement a basic filter by reading only these 3 pixels in any png, extracting from them the data size and CRC32 sum, then comparing them to those of known malicious files. Keep in mind that you need both the data size and CRC32 sum, as the sum alone would introduce collisions.
The octaPNG code already has simple checks in place to determine if the png being read is an opng or a normal image: https://psychicdebugging.com/gillian885/octaPNG/src/commit/ecc36e943b0bd1b733e58a41964910a43eacc5c3/src/dec.c#L201
>I don't want to deny anons utility but I also don't have any friends working at alphabet agencies, prease understandu.
I understand your concern, opngs were made to be cryptic and difficult to control by design so filtering them will require more "unconventional" approaches... That being said, if opngs got popular it would only be a matter of time before they are treated like ZIP archives and have detectors implemented on all websites. It definitely helps that they're easily recognizable by eye as "clown vomit" as you call it, although it would be trivial to implement a similar png-based format that hides its data behind a normal-looking image.
>The only real countermeasure I can think of would be compressing image files to  try and corrupt the encoded archive
Literally facebook. I would rather you ban clown vomit on sight rather than degrade anons' lossless pngs.

>>5662
Thanks for the patch and for reading my code, I didn't expect this to gain any attention.
>pkg-config
I'm reluctant to add an extra dependency since the program compiles fine without it on both Windows and Linux (other anons are encouraged to verify this) so I'll add it under the OpenBSD build instructions for now.
>You should probably use getopt()
What's wrong with using parg? Also getopt is not on Windows.
>You're using floats to deal with exact numbers (square image height/width, filesize)
That's not exactly true. Filesize (bytes), width and height (pixels) are all integers, but the width and height are derived from the filesize as floats first then rounded up into integers. In this case I don't care about precision or the actual decimal values, I only care about whether there is a fractional part or not so I can round it up.
>Recursive Make Considered Harmful
>installing and uninstalling the program in your Makefile
>what I truly recommend is using Meson as the build system instead
>You could write a man page
I'll look into it.
>You should break lines in your Markdown like everyone does with source code
Could you elaborate?
>try writing a package and sending it to a distro to see the kinds of things any repository would want to change in your program before accepting it
Not sure there's much benefit in doing that honestly.
>you mandate static linking
Not at all, dynamic linking works just as well but I personally don't like it for several reasons. You're free to remove the -static flag.
>You require -O1
You're free to remove that too.
>There's a bug: the argument to tolower() isn't cast to unsigned char
Thanks, fixed. Do I need to cast the *a==*b line as well?

>>5663
>it will take some processing power to detect steganography
Not really, the opng "header" is only 3 pixels (see above). Unless you're talking about decoding the entire image, that would be crazy... I don't think of opngs as a form of steganography though, rather a (very simple) form of cryptography.
>But you only need to do this for popular steganography formats.
What are those formats? Serious question.
>would it be better to let it slide and argue you have no way to know there are cp in those pictures and it may as well be random (plausible deniability)?
That would be a good approach, at least until (if) opngs become the next ZIP as previously mentioned.
Replies: >>5665 >>5671
>>5664
It is steganography, hiding/storing information in another. Cryptography is controlling who can understand a piece of information.
<processing power
I meant different kinds of steganography. It is easy enough to detect yours, but not so easy when you want to do that for every image that gets posts on a site for tens of steganography methods.
>popular steganography formats
A look at github: https://github.com/topics/steganography
>PNG IDAT
https://github.com/DavidBuchanan314/tweetable-polyglot-png
>last significant bit
https://github.com/DimitarPetrov/stegify
>binary offset
https://github.com/ytisf/PyExfil/blob/master/USAGE.md#image-binary-offset
>PNG transparency
https://github.com/ytisf/PyExfil/blob/master/USAGE.md#png-transparency
>machine learning
Eg: https://github.com/tancik/StegaStamp
You can combine and layer these techinques together and it would be nearly impossible to tell if there something hidden behind 7 proxies.
Replies: >>5689
>>5662
>meson
You mean the build system built for freedesktop faggotry? Personally I am allergic to tools they use, can you explain why it is better than the rest?
Handmade Makefiles takes more work, but a developer should know enough of his software to do it.
Replies: >>5671
>>5662
> - You could write a man page.
You can use perl's pod2man or asciidoc/asciidoctor.
https://linuxtidbits.wordpress.com/2013/08/21/wtfm-write-the-fine-manual-with-pod2man-text-converter/
Replies: >>5671
1606351745173.png
[Hide] (366.4KB, 1242x691)
>>5666
Meson produces a compile_commands.json https://clang.llvm.org/docs/JSONCompilationDatabase.html which helps you run linters and use clangd's language server features.

Meson is much faster than every other build system, accelerating the work-build-test cycle. It automatically handles rebuilding the relevant files when you change compile flags or a header (Make doesn't), it doesn't relink if a symbol table hasn't changed, and parallel compilation always works (you can break thread safety in Make by not specifying the dependencies between your source files properly).

In Meson, you specify what you want, not how you want. In Make, if you want to install a file for instance, you write an install step and then you create the right directories, copy the files, set the right permissions, and specify a DESTDIR variable so the user can set it and install to the right directory (/usr/pkg on NetBSD, /mingw64 on MINGW64, / on most Linux distros, and so on). In Meson, you set a boolean that says "please install this executable I told you to build," and it has the right path for the current system baked in and also allows the user to specify his own. This is true for every other aspect of the build system and the main cause for its build definitions being much superior, as Meson is much faster and easier to learn and use while only gaining good features.

Meson automatically handles linker order.

Meson partially abstracts dependencies. The main function for asking for a dependency first checks if the dependency is a special case (OpenGL, pthreads, SDL and many others all greatly vary between systems or have their own unique configuration tool for getting the linker and compiler flags, Meson has special cases for those); then it tries to use pkg-config, then it falls back to linking whatever library has the same name, and lastly, it tries to download, compile, and use a dependency from its repository if you told it to. In essence, you have to know what it does there, it just abstracts away the part where you would write the build definitions to do all of that. It also lets you manually and/or conditionally specify which dependencies get statically or dynamically linked or let Meson's defaults or the user specify them. This is important on say Windows, there you probably want to statically link everything that can be statically linked (Cygwin can't for instance) and that has a compatible license, except for the C library.

Meson abstracts the compiler, but still allows manually specifying compiler flags, both the user and the developer can do this. For instance, I check if I'm using a MSVC-like compiler, and if I am, I manually add /Qspectre to the compiler flags because Spectre mitigations are off by default on Windows for some god forsaken reason.
Meson supports feature testing. You don't write an #ifdef for every single platform, C library, and their versions if you want to do something in case a feature is available or missing. You can ask "If this platform has strlcpy, use it, else if it has libbsd, depend on libbsd-overlay; else if it has libstrl, depend on it and include its header; else add this source file with the implementation to the program". That's also more useful than merely using #ifdef, and it's less work while simultaneously producing better results, because you'll have to maintain those #ifdefs as platforms evolve and you'll have to write new ones for every platform you add. With feature testing, chances are, any platform you add will just work, unless you don't have enough fallbacks for missing features.

Meson has a test framework.

Meson exclusively works with a build directory. You don't have to write a clean step, just rm -rf the build directory. This is also important because package systems nowadays want out of tree builds.

Seriously, I've used CMake, POSIX Make, BSD Make, Autotools, and Meson is the only good build system I know. The others don't even compete. You have to ask yourself how you would even do most of the above with Autotools or Make. Most of it is doable with CMake, but you have to be very careful with CMake and the CMake DSL is inferior to Meson's.
There's an APUE exercise that involved writing a library and some tests, I made the mistake of using Make because I hadn't even heard of Meson back then, just writing the Makefile took more time than I would have taken to learn Meson and write better build definitions with Meson.

>>5664
>I'm reluctant to add an extra dependency since the program compiles fine without it on both Windows and Linux
True, but it's a build time dependency that makes a platform work without breaking others.

>What's wrong with using parg? Also getopt is not on Windows.
I don't see anything wrong with it, but I don't see anything right with it. It's best to use the standard interface in such a case because it's less code for you to maintain, every C programmer knows the standard interface, and it leads to smaller binaries.
Less lines of code, less to learn, smaller binaries, that's a better program.

MinGW bakes a getopt() into your executable if you use it. Your program already doesn't work on Visual Studio because the program wants a GCC-like compiler command line interface and the Unix rm command, and the list of things VS doesn't have is only going to grow as you add targets to the make file and the program grows. Either way, you could simply plug in a getopt() implementation on Visual Studio. I think musl's getopt() is the best.

>You're free to remove the -static flag.
True, but the issue here is that it requires a patch. A patch might break every release. It should be settable through the make command, without touching the source code.
The things that need to be patched to get the program to build or do something essential like supporting dynamic linking grow with the program, there's going to come a point where people won't know what to do anymore. Even if they know what to do, not everyone is going to give it the time of day, and they shouldn't have to.

You should look at the repositories of good distros and systems like say OpenWRT and pkgsrc, and look at the package for programs written in the same language and with the same build system as yours, and then look at the kind of patching they do to have the program the way they want. Ideally, you should learn from their build fixes and implement them without breaking other platforms, and come up with a way for them to do whatever else they want to do without touching the source code. A program should build by default on as many platforms as possible. Most customizations are easy to parametrize. Every time your source needs to be touched to build, or an option needs to be set to make the build work, that's a portability bug. Every time someone has to touch your source to enable debug symbols or set the optimization flags they want, that's a bug.

>Could you elaborate?
Put a line break in your Markdown before you reach 80 columns. That hard line break won't show up when converted to other formats. Format Markdown documents like you format source code.

>Do I need to cast the *a==*b line as well?
No. tolower()'s argument needs to be EOF or a value that can fit inside an unsigned char, otherwise it's UB.

Any char with the high bit set on a platform where char is signed is going to trigger that. That happens for instance with UTF-8 text on x86. Technically, the code doesn't work with Unicode in general even after that fix because it won't lowercase Unicode, but that's impossible to fix in Standard C, although you can come closer to something that works with the wide character interfaces. I wouldn't bother.

>>5669
I write mdoc by hand. It takes about a day to read the man page, copy a template, and fill it out to while using someone else's man page as a reference. It's not a complicated format. If you run into a system that doesn't support mdoc (you won't), it can be converted to the older, inferior Unix man format.
I recommend using OpenBSD man pages as a reference (all of its man pages use mdoc), the system also has a template in /usr/share/misc/mdoc.template
https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/share/misc/mdoc.template
https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/usr.bin/env/env.1
Replies: >>5677 >>5689 >>5690
>>5671
>Meson features
Nice explanationshilling, I see how it is useful to you. But I am not convinced, I need to compare other build tools since I don't have much experience in writing build automation.
Replies: >>5678
>>5677
If your project has more than only a few dependencies, your best options are CMake and Meson. Otherwise, just use Make.
Replies: >>5688
>>5646
can't you just
cat image.png files.zip > openinwinrar.png
Replies: >>5681 >>5689
>>5679
That's an ancient techique that was already banned at cuckchan a decade ago.
Replies: >>5689
>>5678
Make sucks for everything, including the smallest of projects.
That anon is already picking between breaking one platform or using pkg-config because of Make brain damage. His code has a "TODO use strlcpy" comment, he can't feature test for the presence of strlcpy with Make, just figuring out the right concotion of #ifdefs to write for that is more effort than learning Meson and will produce worse results.

The sheer amount of suck in any build system other than Meson is not funny. I've spent way too long fixing Autotools and CMake garbage. I'm fixing an Autotools project right now. Do yourself and the world a favor by not using that stuff.
Replies: >>5689 >>5690
The gitea instance where I uploaded octaPNG is having connection issues, so I'm (permanently?) moving to another instance: https://git.creepercreep.fr/gillian885/octaPNG

>>5665
Great examples, thank you.

>>5671
>Meson
Those are some very impressive features, especially the way recompilation and dependencies are handled. I'll consider Meson in future projects and maybe this project as well if it grew more complex later on... But for now I think it would be overkill to use Meson for such a small project, especially considering it has a dependency on Python which I would rather not require.
>it's a build time dependency that makes a platform work without breaking others.
Alright, I've added pkg-config as an optional dependency that is used by default.
>I don't see anything wrong with it, but I don't see anything right with it.
If it ain't broke I won't fix it. parg works nicely for octaPNG and is already being maintained by someone else.
>It should be settable through the make command
Good idea. I've removed all the recursive makefiles and implemented only one makefile that accepts pretty much every option you can think of in a configure-like fashion, so it may be used right away in a predictable fashion. I've also made it strictly POSIX-compliant so it now plays nice with bmake, pdpmake, and even nmake for Windows 95. If you have time do check out the implemented options or read the examples of their usage:
https://git.creepercreep.fr/gillian885/octaPNG/src/branch/master/Makefile
https://git.creepercreep.fr/gillian885/octaPNG/src/branch/master/INSTALL.md#examples
Since the makefile is now POSIX-compliant and all compilation flags can be controlled, I've relaxed the prerequisites for compilation under "Building for other systems".
>Put a line break in your Markdown before you reach 80 columns.
What?.. No, I'm not gonna do that.
>Technically, the code doesn't work with Unicode in general even after that fix
It doesn't matter, I'm using it solely to detect the .png extension and invalid NTFS filenames, both of which are ASCII only. The program in general works fine with unicode filenames including emojis
>You could write a man page.
Done. It's in roff though, if you have a tool to convert it to mdoc do share.

>>5679
>>5681
PNGs with concatenated files at the end are not valid and most if not all websites will "correct" them automatically by removing the extra data. AFAIK the only way to include data in a PNG without affecting the image is by using IDAT chunks as seen in >>5665, and even then the data may easily be removed by websites and photo editors to save space.
The reason I chose to encode data in the PNG pixels themselves is that they're the only part of the PNG that is never altered... That is, unless the website you're using automatically degrades PNG files in some way (e.g. makes them indexed, resizes them, adds a watermark...etc) so they're no longer lossless.

>>5688
>TODO use strlcpy
I was gonna pull it from the OpenBSD source and include it into mine anyway, there's no need to depend on OS-specific code on the target machine... That line was added simply because I found strlcpy to be safer than strcpy after learning about it ITT, although the way I'm copying strings in my code is already bounded so I may not need strlcpy after all.
>>5688
I looked around since I don't have time to test out 3-4 build systems right now. Here is what I found about Meson, it is easy to see why it is good from what you and >>5671 said, so I look for the bads instead.
>cross-compiling support is(was?) weaker than cmake, especially when building dependencies that uses cmake
>little flexibility, rigid project layout expectation, you need to format your project just like what meson expects
I also found the good stuff such as better syntax and speed.
Never used it, I can't say how rigid meson is to project structure. But being confined by a build tool sounds like little gain for a lot of restriction. How do you deal with this or are you completely on board with meson's project layout (it is not a problem for you)?
Replies: >>5691
>>5690
Meson doesn't specify a project layout beyond requiring a dedicated build directory which can have any name.
Cross compiling under Meson is badly documented and buggy. I've also run into a limitation: it won't let you depend on a library on the host and the build machines simultaneously.

Another thing about Meson is that it's not as portable as Autotools or CMake. You can't port your program to 9front or UnixWare 7 with it, and it doesn't support tcc, cparser, or other such obscure systems and compilers. Meson's integration requires adding code to Meson itself to support all of those systems and compilers, whereas Autotools and CMake leave that up to you, so if you put the effort into it, you can probably port your programs to LynxOS and pcc and the like. Well, if you put effort into it, you can add that support to Meson.

I'm this guy btw >>5153. I'm trying to port my stuff to every single system and compiler Meson supports, right now I'm unable to port to any more only because I don't have access to them. I can't get an AIX or HP-UX machine and I can't get nvidia's C compiler. I also need a more modern computer to virtualize GNU/Hurd.
nim.jpeg
[Hide] (82.4KB, 820x480)
nim language
Replies: >>5995
Procrastinating fixing another project that uses Make and only builds on Linux... and AIX. At least the source code says it builds on AIX, I doubt it does. It also mentions Ultrix but I'm sure it doesn't.
Oh and it doesn't actually build on Linux either, if simply running "make" doesn't work and they want you to specify a bunch of configuration options then it's broken.
>>5805
>C with my pet peeve fixed and all the other issues kept in, episode #192874912
Yawn.
my_wendy.jpg
[Hide] (371.7KB, 1440x1200)
I'm writing packages for C programs. I now hate C even more. Jesus, where did it all go so wrong?
default.png
[Hide] (92.2KB, 1263x1381)
I wrote and uploaded the page generator I use for my website's microblog.
https://notabug.org/likho/microblog.py/src/master
If other anons like it and use it, I think it would be fun to make a directory or webring of other microblogs.
Replies: >>6566
>>6557
Good work anon, the tags are a nice touch.
extremely_painful.png
[Hide] (73.7KB, 226x261)
Boy, I sure love Unix.
language: c
const pid_t pid_t_max = ((uintmax_t)1 << (sizeof(pid_max) * 8 - 1)) - 1;
Replies: >>6585
slavface.jpg
[Hide] (6KB, 220x224)
>>6584
And nevermind that I passed the wrong identifier to sizeof, I posted the code as soon as I had to write it.
When should I write my own application protocol?
I am writing a program that talks to each other across the internet. The language is C. The data that's going to be transferred are
>specific requests with known sizes
>arbitrary binary data, variable length
I am torn between rolling my own plain text protocol, http/json or something else.
Security would be an issue if I roll my own protocol. But I am not sure about pulling in a dependency such as libmicrohttpd.
Another point is there can be multiple independent instances of the program running on the same machine. They can talk to each other and also to instances on another machine. My plan for this is run a manager/software nat program to masquerade remote connections, and use unix sockets for local connections. Is this dumb?
Replies: >>6730
>>6716
Probably when you can write one that is better than a preexisting protocol.
What happens when a nightmare and a traumatic experience marry? Soon they have a little JSX (a.k.a. JavaScript XML) running around and kicking people in the knee.
https://wikipedia.org/wiki/JSX_(JavaScript)
After reading the strlcpy paper from OpenBSD I implemented my own strlcpy and strlcat. They work fine but I noticed they're much shorter than the OpenBSD implementation, so is there something I'm missing?
For reference their implementation is here:
https://github.com/openbsd/src/blob/master/lib/libc/string/strlcpy.c
https://github.com/openbsd/src/blob/master/lib/libc/string/strlcat.c
And my implementation is as follows:
language: c
size_t
strlcpy(char *b, const char *a, size_t len_b)
{
    size_t total;
    
    for (total=0; total<len_b && (*b=*a); a++, b++, total++);
    if (total && total==len_b) *--b = '\0';
    while(*a++) total++;
    
    return total;
}

size_t
strlcat(char *b, const char *a, size_t len_b)
{
    size_t total;
    
    for (total=0; *b; b++, total++);
    for (; total<len_b && (*b=*a); a++, b++, total++);
    if (total && total==len_b) *--b = '\0';
    while(*a++) total++;
    
    return total;
}
Replies: >>7308
>>6892
The OpenBSD version is very performance-oriented, they minimize the instructions in the loops. Your version looks like something Musl would write. Usually, OpenBSD libc code is focused on having the best algorithm and minimizing instructions to reduce the cost of each iteration. Musl writes very compact C source. 

Your strlcat() dereferences b when len_b is 0.
Replies: >>7309
>>7308
>they minimize the instructions in the loops
>minimizing instructions to reduce the cost of each iteration
That explains it, thank you. I do tend to write compact code but I still have a lot to learn when it comes to performance optimization.
>Your strlcat() dereferences b when len_b is 0.
I'm guessing you're talking about this line:
language: c
for (total=0; *b; b++, total++);
I wrote it under the assumption that a zero length string is NUL terminated, in other words char *s[1]={0} ... Is that not the usage case for strlcat?
Replies: >>7311
>>7309
len_b isn't the string length of b, it's the size of its buffer.
You can create a valid pointer that can't be dereferenced in C by calling malloc(0) or incrementing a pointer until it points to one past the end of the object it points to.

If you look at the OpenBSD source, it doesn't dereference b if len_b is 0 and it doesn't read more than len_b bytes off of b.
Replies: >>7316
>>7311
>len_b isn't the string length of b, it's the size of its buffer.
Right, my bad. Here's the fixed function:
language: c
size_t
strlcat(char *b, const char *a, size_t len_b)
{
    size_t total = 0;
    
    if (len_b) for (; *b; b++, total++);
    for (; total<len_b && (*b=*a); a++, b++, total++);
    if (total && total==len_b) *--b = '\0';
    while(*a++) total++;
    
    return total;
}
Replies: >>7321
>>7316
Now if b doesn't have a terminator and len_b is not 0, it still overreads the buffer. 
OpenBSD's man page fails to specify whether strlcat() is supposed to cope with this, but the code does.
Replies: >>7330
>>7321
>if b doesn't have a terminator
If it's not NUL terminated then that would be incorrect usage, how will the program know when b ends?
>but the code does.
Could you elaborate?
Replies: >>7341
>>7330
OpenBSD's strlcat assumes b's string length is len_b if it doesn't find a terminator within len_b bytes.
Replies: >>7343
>>7341
Ah... Well that's definitely incorrect usage, so no need to handle it on my end.
scr.png
[Hide] (3.5KB, 648x508)
octaPNG GUI version now released
Some months ago I released a tool for converting arbitrary files to PNG images and back, it was CLI-only and now there's a GUI version made with SDL2. As usual there are binaries for Windows and Linux available, fully statically linked, so you can grab one and use it right away: https://git.creepercreep.fr/gillian885/octaPNG/releases

Side note: the project now builds with Meson as well as Make, however I found Meson to be quite inflexible... Some things that I wanted to accomplish but couldn't:
<have meson build the GUI version only if SDL2 exists or the user requests it explicitly
<if SDL2 isn't available build only the CLI version without throwing errors
<work with #include <SDL2/SDL.h> instead of only supporting the hazardous <SDL.h>
Replies: >>7532 >>7540 >>7917
>>7483
All of that is doable with Meson.
You'll want to use the required or disabler keyword arguments of the dependency() function: https://mesonbuild.com/Reference-manual_functions.html#dependency
disabler is more powerful but a bit hard to grasp, required is more like the programming one is used to outside Meson. And you'll also want to get into Meson options: https://mesonbuild.com/Build-options.html

Generally, one should avoid the sort of "automagic" dependency you're thinking about adding to octaPNG because operating systems don't like it. It should build your choice of GUI/CLI/GUI+CLI by default and fail if anything is missing, then there should be an option to choose a different configuration, but always explicitly, nothing automatic. Automatic means SDL2 can go missing someday due to a packaging error and the build will succeed but not produce the result the package maintainer expected, and not many people will meticulously read all the build output to notice that. Gentoo has an article about this: https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Automagic_dependencies

Also, you should put the code that is common between the GUI and CLI versions into a library and always statically link it if only one version is being built, or let the user choose between static and dynamic linking if both versions are being built. 

And why is including SDL.h hazardous? I don't understand.
Replies: >>7544 >>7547
Not sure if this counts as something I am working on, since I did it for work. I have just implemented a build pipeline for unit testing parts of an embedded C program.
The program is very poorly written, or I am new to embedded software that I haven't picked up how they do things. The program is full of headers that include each other and eventually most headers. Hardware sensors implementations exposes their structs as global variables for reading their values. I have reimplemented parts of it and I am testing those parts. The program cannot be compiled for other targets because chip vendor's library is leaking to many parts of the program, except those I have reimplemented.
The problem is to build and link with required object files. For example, for a source file "calculator.c", I want to write a test "calculator_test.c". This is easy. But consider "complex_algo.c" which uses functions from "calculator.h". I can either mock "calculator.h" or compile and use it. Coming with compile commands for each of them is not hard. To automate it is tricky.
I uses include path for header override, to use only parts of the original header. The copied headers are not in sync of the original. This is not a good solution, but it will have to do for now. 
To identify required objects, I use gcc with md and mp on the pass of the test source file to test objects. With the .ds, I can extract the included headers and identify which .o are needed for that specific test binary. .d files are Makefiles, and I don't want to write a parser/regex for it. I call make in make to process the rules. Originally, I append the rules into .ds. But for some reasons, make isn't reading and restarting itself. I had to make .e files and explicitly include them. The rules are transformed into prerequisites for binary targets.
I didn't even know I could do this, they are not paying me enough for this magic.
Replies: >>7547
>>7483
BTW, the Windows way of distributing things is with an installer instead of a loose .exe. 
The 2 main free software ways of writing Windows installers are NSIS2 https://nsis.sourceforge.io/NSIS_2 and Inno Setup https://jrsoftware.org/isinfo.php

NSIS2 is more like a Unix hacker project: you write a language that is modeled after assembly into a text file and then you run a compiler command that converts it into an executable.
Inno Setup is more like a Windows thing, it has its own IDE. San Andreas Multiplier uses NSIS2, GoG uses Inno Setup.

NSIS2 has a lot of jank and its documentation still refers to things it added in 2006 as "new," but the fact that it's a programming language and that you can extend it by writing a .dll and using a FFI within your installer script means you have a lot of power to work around Windows' quirks (and there are a lot, it's the worst OS ever). I haven't used Inno Setup.
I use NSIS2 mostly because it's the thing I tried, but also because it's easy to script as it's command line, I automated producing installers with every commit and tag.
Replies: >>7547
>>7532
POTD.
>>7532
>Generally, one should avoid the sort of "automagic" dependency
Heh, didn't know that was a thing. I agree though, I'll just leave the current default as CLI+GUI.
>Also, you should put the code that is common between the GUI and CLI versions into a library
Not sure about making octaPNG a library but this reminds me that I need to tweak the Makefiles to build objects instead of a binary in one go. Might have an issue with the system-dependent object extension though...
>You'll want to use required
Tried that, but then if SDL2 is missing Meson never bothers installing it on its own and never prompts the user to do so. Also required makes the dependency automagic.
>disabler is more powerful but a bit hard to grasp
"A bit hard to grasp" is quite the understatement. The Meson manual overall is largely illegible, almost every page leaves me wondering "Did I understand this feature correctly? Will this let me achieve the goal I have in mind?" and almost every time the answer is no and no. I would very much like to know how to translate simple Make rules such as:
make octapng        # build the CLI version and nothing else
make octapng-gui    # build the GUI version and nothing else
make all            # build both or fail
into Meson syntax.
>And why is including SDL.h hazardous?
SDL.h is the name of the main SDL header for both SDL 1.x and 2.x, and also both versions share a part of the API but not the same behavior. So #including <SDL.h> is ambiguous and hence hazardous because you're not specifying the version, and keep in mind that both versions can co-exist on the same machine... The correct way of dealing with SDL headers is placing version 1 headers into SDL/ and version 2 headers into SDL2/, then #including the needed header accordingly. This is what the SDL org recommends and what every single package manager does, except Meson.

>>7534
Can you share the source?

>>7540
>an installer instead of a loose .exe
Unless your program needs tight OS integration, packaging it as an installer is the worst decision you can make...
<unneeded steps and time wasted before the user can finally use the program
<can't carry around a single exe and use it across machines
<must wrestle with UAC and other privilege shenanigans on modern Windows
<package size increases due to the installer itself (which you may delete) and the uninstaller (which you may not delete)
<uninstaller may or may not delete all files / registry keys / libraries...etc
Granted that an installer would be nice to have as an option alongside a "loose" binary, it makes no sense for a small single-executable program. But if I had to choose an installer it would 100% be NSIS; very lightweight and still compatible with legacy Windows versions.
>GoG uses Inno Setup
It says on the website that Inno is 64-bit, but I've run GOG installers on 32-bit machines before. Was that an older version or a custom build?
>using a FFI
What's that?
>work around Windows' quirks
The nice thing about using natively cross-platform libraries/tools is that I never have to think about such annoyances, and I don't want to. octaPNG was 100% developed on Linux, yet when I tried compiling it for Windows everything "just worked", it was almost magical.
Replies: >>7551 >>7583
>>7547
>if SDL2 is missing Meson never bothers installing it on its own and never prompts the user to do so
You need to add SDL2 as a subproject.
https://mesonbuild.com/Subprojects.html
This sort of dependency is actually fine because a packaging system will have subprojects disabled.

>The correct way of dealing with SDL headers is placing version 1 headers into SDL/ and version 2 headers into SDL2/, then #including the needed header accordingly. This is what the SDL org recommends and what every single package manager does, except Meson.
Meson just uses pkg-config, seems SDL2's pkg-config file adds /usr/include/SDL2 (or the operating system's equivalent) to the include path. It's completely harmless as long as you're not using both SDL and SDL2 at once because user include directories come before system include directories.

I looked at the source and there's a commit specifically about this: https://github.com/libsdl-org/SDL/commit/45c1cc81771123a3a3a632e945dd4fd7a428c92b
It just has to trickle down into packages I guess.


I made the frontends optional save for the requirement that at least least one be enabled and added a SDL2 subproject, here's the patch:
`text
From 37a313e67f4b4b0b1387487d50bbe0121508ac9a Mon Sep 17 00:00:00 2001
From: Anonymous <[email protected]/tech/>
Date: Wed, 9 Nov 2022 17:09:59 +0000
Subject: [PATCH] add SDL2 subproject and make dependencies optional

---
 meson.build           | 73 ++++++++-------------------
 meson_options.txt     |  4 +++
 subprojects/sdl2.wrap | 12 +++
 3 files changed, 56 insertions(+), 33 deletions(-)
 create mode 100644 meson_options.txt
 create mode 100644 subprojects/sdl2.wrap

diff --git a/meson.build b/meson.build
index 91e872f..71b8766 100644
--- a/meson.build
+++ b/meson.build
@@ -30,46 +30,53 @@ deps = [
 install_man('man/octapng.1')
 
 
+if (get_option('cli_frontend') or get_option('gui_frontend')) == false
+    error('at least one frontend must be enabled')
+endif
+
 # CLI version
 #-------------------------------------------------------------------------------
 
-src_cli = [
-    src,
-    'src/octapng.c',
-    'src/ver.c'
-]
+if get_option('cli_frontend')
+    src_cli = [
+        src,
+        'src/octapng.c',
+        'src/ver.c'
+    ]
 
-deps_cli = deps
-
-executable('octapng', src_cli,
-           dependencies: deps_cli,
-           install: true
-)
+    deps_cli = deps
 
+    executable('octapng', src_cli,
+               dependencies: deps_cli,
+               install: true
+    )
+endif
 
 # GUI version
 #-------------------------------------------------------------------------------
 
-src_gui = [
-    src,
-    'src/octapng-gui.c',
-    'src/ver-gui.c'
-]
-
-deps_gui = [
-    deps,
-    dependency('sdl2')
-]
-
-incd = []
-
-# ugly hack to resolve 'SDL2/SDL.h' --> 'SDL.h'
-if not meson.get_compiler('c').has_header('SDL2/SDL.h')
-    incd += include_directories('meson')
+if get_option('gui_frontend')
+    src_gui = [
+        src,
+        'src/octapng-gui.c',
+        'src/ver-gui.c'
+    ]
+
+    deps_gui = [
+        deps,
+        dependency('sdl2')
+    ]
+
+    incd = []
+
+    # ugly hack to resolve 'SDL2/SDL.h' --> 'SDL.h'
+    if not meson.get_compiler('c').has_header('SDL2/SDL.h')
+        incd += include_directories('meson')
+    endif
+
+    executable('octapng-gui', src_gui,
+               dependencies: deps_gui,
+               include_directories: incd,
+               install: true
+    )
 endif
-
-executable('octapng-gui', src_gui,
-           dependencies: deps_gui,
-           include_directories: incd,
-           install: true
-)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..ac460fb
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,4 @@
+option('gui_frontend', type : 'boolean', value : true,
+       description : 'Compile the graphical user interface frontend')
+option('cli_frontend', type : 'boolean', value : true,
+       description : 'Compile the command line interface frontend')
diff --git a/subprojects/sdl2.wrap b/subprojects/sdl2.wrap
new file mode 100644
index 0000000..170814a
--- /dev/null
+++ b/subprojects/sdl2.wrap
@@ -0,0 +1,12 @@
+[wrap-file]
+directory = SDL2-2.24.2
+source_url = https://github.com/libsdl-org/SDL/releases/download/release-2.24.2/SDL2-2.24.2.tar.gz
+source_filename = SDL2-2.24.2.tar.gz
+source_hash = b35ef0a802b09d90ed3add0dcac0e95820804202914f5bb7b0feb710f1a1329f
+patch_filename = sdl2_2.24.2-1_patch.zip
+patch_url = https://wrapdb.mesonbuild.com/v2/sdl2_2.24.2-1/get_patch
+patch_hash = 9952a79eee3e53dc04daac494a4c0b8cd4c062bfe7365c4766a6bfa15c85b52d
+wrapdb_version = 2.24.2-1
+
+[provide]
+sdl2 = sdl2_dep
-- 
2.37.3

`
Replies: >>7552 >>7601
>>7551
Seems I failed to quote the patch properly, here's it in a paste:
https://paste.debian.net/plainh/5c113e71
https://paste.opensuse.org/view/raw/31dfe912
Replies: >>7587
>>7547
>Can you share the source?
Unfortunately, work is closed source. I can share similar examples, if you wish.
Replies: >>7601
>>7552
>Hunk #1 FAILED at 30.
>1 out of 1 hunk FAILED -- saving rejects to file meson.build.rej
Replies: >>7591
>>7587
you're using the wrong command, use git am
Replies: >>7601
>>7591
That's much better, thank you. The repo has been updated.

>>7551
>Meson just uses pkg-config
I'm not talking about Meson finding SDL2 when it's already installed on the system (it does that just fine actually), I'm talking about Meson fetching it manually through meson wrap and using <SDL.h> in that case.
>It's completely harmless as long as you're not using both SDL and SDL2 at once
That's true, however I can think of multiple projects (e.g. emulators, games) that use both; either to build separate SDL1 and SDL2 versions of the same program, or to let the user choose one version and build that.

>>7583
It's no problem, I was just asking to see if I can learn anything from the code or suggest changes.
Replies: >>7610
>>7601
I see you added an icon, why not spend a week or 2 clenching your teeth while you add the icon to the Windows version? https://mesonbuild.com/Windows-module.html
Replies: >>7611
>>7610
>add the icon to the Windows version
Already added using make and mingw, it's surprisingly easy and even took less time than making the icon itself. The how-to is in the win folder.
Replies: >>7622
>>7611
Needs some higher resolution versions:
https://learn.microsoft.com/en-us/windows/win32/uxguide/vis-icons#size-requirements
Because your icon doesn't have gradients or anything like that, you can just make everything 4-bit to save space, no need for the 8-bit alternatives.
Replies: >>7628
>>7622
>Needs some higher resolution versions:
I'll consider it provided they don't break compatibility with older Windows versions.
>no need for the 8-bit alternatives
The 8-bit versions have anti-aliasing which is not possible in the 4-bit versions.
GIF_12-12-2022_16-34-53.gif
[Hide] (180.5KB, 50x36)
2022-12-12_258.webm
[Hide] (1.3MB, 784x592, 00:13)
I just implemented a smooth pixel art renderer (software). It's basically nearest-neighbor except it can draw at any position and size smoothly, you could think of it as every pixel being a vector rectangle. Webm is zoomed in so you can see the pixels.
Replies: >>7875 >>7879 >>7898
>>7874
That's pretty cool anon. How does it perform when there's tons of pixels?
Replies: >>7877
>>7875
I'm not sure what to compare it to, I don't have any other kind of function that's capable of upscaling.

I tried it against a normal image drawing function and the normal function is about 70 times faster if the image is solid, 9 times faster if the image is semi-transparent. Those figures are slightly off because the other functions don't have the capability to zoom in built into them in any way, but it's mostly representative.

Solid pixels are very fast to draw since you can copypaste entire pixels or even memcpy entire rows of pixels. Semi-transparent images are a lot slower to draw because you have to do color blending for 4 separate channels per pixel.
GIF_12-12-2022_19-27-03.gif
[Hide] (404.7KB, 230x90)
zoomy.png
[Hide] (16.9KB, 736x163)
>>7874
Hooked it into my bitmap font renderer. It didn't end up being as good as I imagined, I hoped I could scale up text in by small increments like 1.2x, but it actually looks LESS readable unless it's >1.5 or so. I guess that still works though, 2x is too big of a difference.
Replies: >>7880 >>7882
>>7879
Can you make one for /tech/ banner?
Replies: >>7882
GIF_12-12-2022_19-51-46.gif
[Hide] (2MB, 736x166)
>>7879
Works really well when the text is moving, though I didn't actually intend to use this for games so I'm not sure how useful that is.

>>7880
I'm too lazy to think of what text to put on it.
Replies: >>7885
>>7882
zzz/tech/
Replies: >>7886
banana.gif
[Hide] (416.7KB, 300x100)
>>7885
Replies: >>7887 >>7888
>>7886
Added.
>>7886
I like that demo style of enlarging and shrinking the text. Well done, anon.
colors.gif
[Hide] (474.7KB, 300x100)
Tried different colors.
I think I'll try to release the source code for this, it's basically a program that generates the frames for this banner, you can then just use a imagemagick command to create the gif. Need to untangle a lot of my personal boilerplate libraries though since they aren't related.
Replies: >>7898 >>7913
>>7874
I don't think this is nearest neighbor, colors are obviously getting smoothed.

>>7889
I prefer the colored version.
>I think I'll try to release the source code for this
Please do!
>can't upload .zip files
Why.zip?

>>7889
https://sundee.neocities.org/dump/zzzbanner.zip
Got distracted cleaning up my own codebase, but here's the source code. I tried to remove as much unnecessary stuff as possible but it could still be more minimal.

It only works on Windows and probably only compiles with GCC because that's the only context that is relevant to me. It should work on Linux just by porting the relevant functions from lib_windows.c file though (mostly opening/saving files). The program used to open a window that shows the animation, but I left it out because it would be much less portable.
Replies: >>7915 >>7917 >>7928
>>7913
Nice site. I will port it to Linux if I have some time.
zzzbanner.zip.png
[Hide] (93.7KB, 180x181)
>>7913
That's a pretty cool site, thanks for sharing the source anon.
>>can't upload .zip files
>Why.zip?
You can use octaPNG for that (see >>7483 >>5646)
>>7913
Christ, where do you even learn to program like this?
Replies: >>7929 >>7930
>>7928
The "I don't give a shit what some imageboard nigger thinks about my coding habits" school.
1671056227441895.jpg
[Hide] (431.5KB, 748x1102)
>>7928
If it works, it works.
>>1612
Thanks for this post in remembrance of Terrry A. Davis, Anon.
le_ebin_snek_gaem.gif
[Hide] (608.7KB, 299x299)
Does anyone have any idea what the literal most powerful toaster is today? I kinda want to try my hand at making a toaster waifu I can play sneks with all day.
Toaster-Feature-768x424.jpg
[Hide] (14.6KB, 768x424)
I'm currently hopping on the AI train looking into gpu server rentals and hitting up colo companies because holy god they fucking rape you with these hourly fees.

Im hardly a programmer anymore, turning into some server jew. Cant wait to start overprovisioning and deadpooling.
Replies: >>7960
>>7959
Good luck Anon. Use your blessings for great good.

>deadpooling
What's that?
Replies: >>7961
>>7960
Deadpoling is when the host can't deal with shit and just flakes off.

Not very jewish actually when i spell it out like that.
Replies: >>7968
>>7961
>Not very jewish actually when i spell it out like that.
Hehe that's 'exactly' kike-ish, you ask me. :^)
frozen-planet2_2080292c.webp
[Hide] (26.6KB, 460x288)
i was writing an imageboard front end but the dependencies kept pulling in gay shit and i kept running into issues with os configuration and edge cases in bash and make. day of the seal when
Replies: >>8016 >>8019
>>8015
>bash and make
You're the one who decided to make it hard on himself.
Replies: >>8019
>>8015
What edge cases?
>>8016
Not necessary hard.
I generally don't like non-algorithmic optimizations, but I've been thinking about restrict in C. It might make sense to use it to say "these function parameters can't point to the same object". like memcpy does:
language: c
void *memcpy(void *restrict s1, const void *restrict s2, size_t);
void *memmove(void *s1, const void *s2, size_t);
That is, using it to document an interface. Instead of saying "s1 and s2 cannot overlap," I use the restrict keyword, and let the C code's semantics spell it out for me. Any optimization the compiler may make on top of these semantics is a nice side effect of expressing intent semantically rather through documentation.

What do you guys think? This and static inside of the brackets of the declaration of array aren't in widespread use, but they're both useful for documenting interfaces and generate better assembly, so I should break the ice and start using them.
Replies: >>8301
>>8300 
restrict is for aliasing  it has nothing to do with overlap
memcpy( 0x10, 0x11, 5 ) is still overlapping even with non aliased pointers
restrict only exists because of the bullshit strict aliasing rule which forces the compiler to reload the cache for pointers that are aliased just in case they point to the same address, restrict is just a 'trust me bro, dont fucking reload this' to the compiler
Replies: >>8330
>>8301
The standard specifically has an example about this: https://www.iso-9899.info/n1570.html#6.7.3.1p9

By the way, I managed to sneak a char str[static 1] declaration into a real program. 

Also, if you combine VLAs and static in a function parameter array declarator, you get this:
language: c
size_t my_strlcpy(size_t dstsize, char dst[restrict static dstsize], char src[const restrict static 1]);
dst must point to an object of at least dstsize bytes, otherwise it's UB. I'm using the code's semantics, not documentation, to say that dstsize is the length of the array dst points to.

One detail is that dstsize needs to be before dst in the parameter list, otherwise it's not in the scope of dst's declaration, and this order is the opposite of what the typical C program and the stdlib itself do. This code is looking extremely alien to me and I came up with it. Do you think this is a good idea?
Replies: >>8331
>>8330
I should have used a standard function as a template example. Also, the const is misplaced: it refers to the pointer, not to the object it points to.

language: c
char *my_strncpy(size_t dstsize, char dst[restrict static dstsize], const char src[restrict static 1]);

Indeed, the fact that such code isn't what we're all used to writing is a source of bugs, but maybe it should be the kind of code we write.
Replies: >>8339
>>8331
seems unnecessary, its already obvious from the name that dstsize is the size of dst
Replies: >>8356
e98d0ea9b11244e3b6264cb825853854058cb4b899516101625b69e7b0a5f423.png
[Hide] (144.9KB, 401x316)
>>8339
That's true. I think I'll start using restrict to document through semantics that pointer parameters may not overlap, and [static 1] to document through semantics that a parameter must be non-null, but I won't use the VLA trick.
BTW, one thing I noticed is that good testers are often terrible at actually writing programs. Has a more experienced anon noticed a similar pattern?

I guess maybe passing their manual and automated tests gives them confidence their code is good, even when it obviously isn't.
Replies: >>8359 >>8368
>>8358
most people dont write good code, thats why theres always a 500th+ update, good code takes too much effort, good code is wizard code not normal code, only meant for performance critical things which yeah, bugchasers probably cant do whats needed at that level like typepunning, pointer arithmetic, jump tables etc. all the stuff you wouldnt/shouldnt do with normal code since its error prone and a guaranteed mess unless you know exactly what youre doing
Replies: >>8377
>>8358
QA is often slotted as an entry level position to sort out people who are competent enough to write things at whatever level.  I personally find most QA people to be sloppy and incapable of thinking about how to think up clever ways to trip things up, or, often even to merely be thorough enough to go through step by step what an end user is going to have to do, document what that might be, and then aactually establish a meaningful end-to-end style test.

But if a QA guy can be decently rigorous and straddle some kind of ballance between knowing roughly how things are supposed  to work inside and roughly what the typical use cases would be, then it's still a valuable position.  I alpha test my own stuff always, and often recruit somebody else to co-alpha it for me becuse usually I'm doing stuff for some other person's or groups' needs, but not having beta testers is a good way to go ahead and face plant.
>>8359
>most people dont write good code
Correct.
>good code is wizard code
No.
Writing software is a matter of design for maintainability. Every part of the software should be ideally self-documenting, modular and kept simple. Wizard code doesn't mean it is good. It means it is hard to understand and change, because requirements always change.
The way how people write bad code is by not making any design. It is the difference between kids lumping sand together to build a somewhat castle looking hill and a well designed building. Bad code are unplanned, difficult to be understood and also perform poorly. Good performance can get you sales and usage, but it is far from being good code. Good code is simple because of well designed abstractions and complete separation between modules.
t. worked on dog shit code
Thread is autosaging... Shall I make a new one?
Replies: >>8534
>>8438
Sure, I was going to make one but I was too lazy
meme-pajeet-indian-it-code-programming-1.jpeg
[Hide] (94.3KB, 594x768)
No rush guise. Rajish here will whip up some code that will make a new thread for us soon, like any day now tbh.
Wondering if anyone has tried and true recommendations for the best CBD gummies?

⊖ Thread has reached reply limit.


500 replies | 102 files
Connecting...
Show Post Actions

Actions:

Captcha:

Select the solid/filled icons
- news - rules - faq -
jschan 1.4.1