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

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

058

058

Күн бұрын

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!)
Part IV: The Live Coding Stream (comment if interested, so I can stream!)
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
@user-fc8xw4fi5v
@user-fc8xw4fi5v 12 күн бұрын
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: kzfaq.info/get/bejne/g92llbReta3SlYU.htmlsi=RhUrpyLDdy3E9mBV
@balram8223
@balram8223 7 күн бұрын
i guess you should do implementing my own list next
@happygofishing
@happygofishing 9 күн бұрын
This video will blow up.
@nizidev
@nizidev 9 күн бұрын
Great video
@KeithKazamaFlick
@KeithKazamaFlick 13 күн бұрын
very good video
@roejogan1759
@roejogan1759 13 күн бұрын
nice
@grenadier4702
@grenadier4702 9 күн бұрын
Nice job. How much time did it take?
@user-fc8xw4fi5v
@user-fc8xw4fi5v 9 күн бұрын
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 10 күн бұрын
this is neat, I'm curious how you'd actually do print to screen though. Like rewrite cout
@user-fc8xw4fi5v
@user-fc8xw4fi5v 10 күн бұрын
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.
@user-fc8xw4fi5v
@user-fc8xw4fi5v 10 күн бұрын
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 9 күн бұрын
Do you knew this guy before hand or did you discovered him ? Just interested in how algorithm works.
@grenadier4702
@grenadier4702 9 күн бұрын
For example, on posix-compliant systems it's the write syscall
@hawks3109
@hawks3109 8 күн бұрын
@@user-fc8xw4fi5v 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
Compilers, How They Work, And Writing Them From Scratch
23:53
Adam McDaniel
Рет қаралды 82 М.
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 1,5 МЛН
When You Get Ran Over By A Car...
00:15
Jojo Sim
Рет қаралды 11 МЛН
Каха ограбил банк
01:00
К-Media
Рет қаралды 11 МЛН
10 Nooby Mistakes Devs Often Make In Python
24:31
Indently
Рет қаралды 48 М.
Physicists Claim They Can Send Particles Into the Past
7:21
Sabine Hossenfelder
Рет қаралды 213 М.
This AI changes the internet forever: WebSim deep dive
37:27
AI Search
Рет қаралды 167 М.
God-Tier Developer Roadmap
16:42
Fireship
Рет қаралды 6 МЛН
Best POKE Ever? For Commodore 64
22:21
8-Bit Show And Tell
Рет қаралды 34 М.
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 455 М.
Malware Development: Processes, Threads, and Handles
31:29
Should you learn C++?? | Prime Reacts
20:29
ThePrimeTime
Рет қаралды 325 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 139 М.
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 1,5 МЛН