Reinventing the wheel: write your own printf from scratch! (part i.i)

  Рет қаралды 3,471

wintc

wintc

Күн бұрын

Part I: The Demonstration
Part II: The Implementation (comment if interested, so I can upload!)
Part III: The Unit Tests (comment if interested, so I can upload!)
Test it yourself: github.com/wintcape/string_fo...
The main function is located @ test/src/main.c.
Part II of the videos will explain most of the stuff in this repo.
0:00 Introduction
2:25 Strings
4:50 Integers
8:59 Floating point numbers
12:40 File info
14:03 Arrays
16:46 Edge cases
19:54 Padding
26:15 Wildcards
27:30 Closing points
28:57 Example

Пікірлер: 15
@wintc
@wintc Ай бұрын
NOTE: At the end of the video, I show an example where we generate string padding on the fly using wildcard format modifiers. This evaluates down at compile-time to the value of the longest **possible** key name string; but, you could also significantly improve the appearance of the output string from what is shown in the video using existing functionality by simply storing in your keymap container a field such as `longest_key_name`. Each time you add a key binding at runtime, update `longest_key_name` if it is shorter than the name of the key being added; then, have your wildcard generate the padding from `longest_key_name`--since wildcards are evaluated at runtime, it works in a way that printf cannot! This way, string_keymap only ever prints **exactly** as many characters as it needs! (In the video, there's extra padding because the key names I used were a lot shorter than the max). Watch me implement the fix here: kzbin.info/www/bejne/g6jYk4Rjhayhm7Msi=RhUrpyLDdy3E9mBV
@happygofishing
@happygofishing Ай бұрын
This video will blow up.
@roejogan1759
@roejogan1759 Ай бұрын
nice
@nizidev
@nizidev Ай бұрын
Great video
@KeithKazamaFlick
@KeithKazamaFlick Ай бұрын
very good video
@balram8223
@balram8223 Ай бұрын
i guess you should do implementing my own list next
@grenadier4702
@grenadier4702 Ай бұрын
Nice job. How much time did it take?
@wintc
@wintc Ай бұрын
The main string_format skeleton took only a day or so, but definitely took at least a month to write all my own platform layer stuff + unit tests to achieve proper handling of edge cases.
@hawks3109
@hawks3109 Ай бұрын
this is neat, I'm curious how you'd actually do print to screen though. Like rewrite cout
@wintc
@wintc Ай бұрын
I can do a video on file I/O if you'd like, but it's OS-dependent. So there'd be separate *nix vs Windows videos.
@wintc
@wintc Ай бұрын
Edit: if you want a quick way using libc to print your final string to stdout: #include #include fwrite ( string , 1 , strlen ( string ) , stdout );
@AyushSharma-yf3qu
@AyushSharma-yf3qu Ай бұрын
Do you knew this guy before hand or did you discovered him ? Just interested in how algorithm works.
@grenadier4702
@grenadier4702 Ай бұрын
For example, on posix-compliant systems it's the write syscall
@hawks3109
@hawks3109 Ай бұрын
@@wintc ah okay it's just a system call. I figured there would need to be more work to set up buffers and such first in specific places. I suppose that would be as the asm level though. Thanks for the quick reply! The video idea would be cool, I've always wanted to write a device driver or something that directly controls hardware. I just don't really know where to start
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 150 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 143 М.
Spot The Fake Animal For $10,000
00:40
MrBeast
Рет қаралды 181 МЛН
Smart Sigma Kid #funny #sigma #comedy
00:40
CRAZY GREAPA
Рет қаралды 13 МЛН
Why Isn't Functional Programming the Norm? - Richard Feldman
46:09
I made a Compiler in 25 Days - Here is what I learned
40:59
Alex The Dev
Рет қаралды 52 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 292 М.
Advice for Writing Small Programs in C
1:45:24
Sean Barrett
Рет қаралды 140 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 286 М.
`const` was a mistake
31:50
Theo - t3․gg
Рет қаралды 132 М.
Let's build a mini printf function
45:46
Oceano
Рет қаралды 23 М.