Let's build a mini printf function

  Рет қаралды 30,704

Oceano

Oceano

Күн бұрын

Пікірлер: 54
@minimalSwift
@minimalSwift 9 ай бұрын
my friend, I love your videos! But this miniprintf has a problem. I also put it here so that other can see it. I mean I don't pretend to let you do all the work and criticize. :) It is a small thing, but you pass (va_list) )ap to the next function by value and this causes indefinite behavior: (Quote as per C99) >The type declared is va_list which is an object type suitable for holding information needed by the macros va_start, va_arg, va_end, and va_copy. If access to the varying arguments is desired, the called function shall declare an object (generally referred to as ap in this subclause) having type va_list. The object ap may be passed as an argument to another function; if that function invokes the va_arg macro with parameter ap, the value of ap in the calling function is indeterminate and shall be passed to the va_end macro prior to any further reference to ap So. It might happen to work on one architecture, but not another, due to differences in how va_list is implemented between architectures. (it did not work on my Mac M1 for instance, I was getting rubbish printed out! Then I double checked the code). > It is permitted to create a pointer to a va_list and pass that pointer to another function, in which case the original function may make further use of the original list after the other function returns. Solution is easy. Use a va_list pointer. int print_format(char specifier, va_list *ap) Thank you for the video. I loved the recursive implementation of the digits... :)
@onaecO
@onaecO 9 ай бұрын
Ty very much for the kind words, and for adding value for other. I'll pin this! ( I just didn't know lol )
@minimalSwift
@minimalSwift 9 ай бұрын
Thank you for your work ! :) @@onaecO
@FilipBalakovski
@FilipBalakovski 6 ай бұрын
I have the same problem with printing garbage values on my architecture (MINGW64). Online debugger (GDB) works just fine. Your fix just gives me a warning and the problem persits :/ Any other suggestions?
@giovannitroiano
@giovannitroiano Жыл бұрын
Thanks
@onaecO
@onaecO Жыл бұрын
👀♥️♥️
@CodingHk
@CodingHk Жыл бұрын
Thanks for this awesome video, C seems to hard to understand and I give it enough time yet still complicated (10hrs+ daily) but this video has helped clear and bring back the hope that I can still learn it. Thank you again
@onaecO
@onaecO Жыл бұрын
10h daily it s massive, congrats!! Agree on everything, C is very very hard. We have to really have patience and study 😁
@adampassaretti9149
@adampassaretti9149 11 ай бұрын
Bro i really need a bit of your work ethics, i'm slacking off too much
@CodingHk
@CodingHk 11 ай бұрын
@@onaecO Yea 10hrs a day, a strict coding bootcamp 😀
@CodingHk
@CodingHk 11 ай бұрын
@@adampassaretti9149 you mean me or onaecO?
@renans.5135
@renans.5135 Жыл бұрын
Awesome video! Kudos from 42 Rio de Janeiro; you've been a great help since my piscine and you continue to be a a spectacular source of help, man. Keep up the good work!
@Yasspums
@Yasspums 11 ай бұрын
does your printf got valid ? im gonna do like him probably
@renans.5135
@renans.5135 11 ай бұрын
It sure did! You can base your work off of him for sure :)
@JenniferBerthe-w9l
@JenniferBerthe-w9l 6 ай бұрын
Hi from 42 Paris !!
@vikassharma-lp9bp
@vikassharma-lp9bp Жыл бұрын
best tutorial on printf, please make video on complete printf :)
@onaecO
@onaecO Жыл бұрын
Ty very much 👊🏻
@pedroalmeida8453
@pedroalmeida8453 Жыл бұрын
42 school, anyone?
@alanishadama
@alanishadama Жыл бұрын
sim
@Ylizz96
@Ylizz96 Жыл бұрын
Ayoo!
@anonym_3241
@anonym_3241 Жыл бұрын
Qwasar?
@ninjingninja
@ninjingninja 8 ай бұрын
I guess it's everyone... Why else?
@JenniferBerthe-w9l
@JenniferBerthe-w9l 6 ай бұрын
Hi !
@vitalis3285
@vitalis3285 5 ай бұрын
I am glad to be your friend, my friend! And thx, for the video, my friend!
@onaecO
@onaecO 5 ай бұрын
Yeah, rately I happen to say "my friend" lol
@noskov5
@noskov5 Жыл бұрын
mate I love your videos. Keep it going
@onaecO
@onaecO Жыл бұрын
Ty very much bro 👊🏻
@giovannivolante7302
@giovannivolante7302 10 ай бұрын
Great work, thanks! A side question: are you using vim? In these case, how do you obtain suggestions and autocompletion?
@onaecO
@onaecO 10 ай бұрын
" Basic Vim settings set number set tabstop=4 set shiftwidth=4 set backspace=indent,eol,start filetype plugin on call plug#begin('~/.vim/plugged') " Essential plugins Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'dense-analysis/ale' Plug 'preservim/nerdtree' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' Plug 'octol/vim-cpp-enhanced-highlight' "Plug 'ryanoasis/vim-devicons' call plug#end() " Set the Airline theme let g:airline_theme='onedark' " Automatic nerdtree toggle map :NERDTreeToggle " COC configuration for real-time diagnostics with clangd let g:coc_global_extensions = ['coc-clangd'] " Enable diagnostics (errors and warnings) and update them on cursor hold autocmd CursorHold,CursorHoldI * silent call CocActionAsync('diagnosticRefresh') " Enter to select suggestion from completion menu inoremap pumvisible() ? "\" : "\" " Configuration for coc-clangd let g:coc_clangd_binary = 'clangd' let g:coc_clangd_args = ['-header-insertion=never'] " Set the color of diagnostic error messages highlight CocErrorSign ctermfg=white ctermbg=red guifg=#ffffff guibg=#ff0000 " Highlight DEBUG statements highlight DEBUG ctermfg=black ctermbg=yellow guifg=black guibg=yellow " Param suggestion highlight CocInlayHint guifg=yellow guibg=NONE ctermfg=yellow ctermbg=NONE highlight link CocInlayHintParameter CocInlayHint highlight link CocInlayHintType CocInlayHint highlight CocInlayHint guifg=yellow guibg=NONE ctermfg=white ctermbg=NONE gui=bold cterm=bold highlight link CocInlayHintParameter CocInlayHint highlight link CocInlayHintType CocInlayHint " Configure ALE let g:ale_sign_error = '✘' let g:ale_sign_warning = '⚠' " Define custom colors for warning text highlight link ALEWarningMsg WarningMsg "highlight ALEWarning ctermfg=red ctermbg=NONE "AUTOSAVE "autocmd TextChanged,TextChangedI * silent write autocmd TextChanged,TextChangedI * \ if &buftype ==# '' || &buftype == 'acwrite' | \ silent write | \ endif " Enable Coc let g:coc_global_extensions = [ \ 'coc-clangd' \ ] " Use Coc for diagnostics (errors and warnings) autocmd CursorHold,CursorHoldI * silent call CocActionAsync('diagnosticRefresh') " Enable inline error and warning display let g:coc_sign_error = '✘' let g:coc_sign_warning = '⚠' let g:coc_status_float_enable = 1 " Enable floating status information let g:coc_status_colors = { \ "Warning": "white", \ } " Set the colorscheme for floating windows au ColorScheme * hi CocFloating ctermfg=white guifg=white ctermbg=black guibg=black
@giovannivolante7302
@giovannivolante7302 10 ай бұрын
@@onaecO Many many thanks
@erikseferi2241
@erikseferi2241 Жыл бұрын
Hello, thanks from 42 Wolfsburg for the video and I also took some inspiration from your Github and made the printf work with bonuses. Do you have slack or discord to reach you out ?
@onaecO
@onaecO Жыл бұрын
Dear friend, u are crazy! printf bonus was a major pain 😂 You should do a tutorial, there is not in yt 🔥 You got me the idea and i just created a telegram group ~t.me/suspectedoceanO We can create a 42 gang ;)
@ynelniino
@ynelniino Жыл бұрын
thank you 🙏🙏
@onaecO
@onaecO Жыл бұрын
Thank you for the comment 🔥
@kellvynrocha3583
@kellvynrocha3583 Жыл бұрын
I L O V E Y O U
@onaecO
@onaecO Жыл бұрын
😂😂😂
@zoenagy9458
@zoenagy9458 11 ай бұрын
i++ is more readable when it stands alone
@oscarms6067
@oscarms6067 Жыл бұрын
what if print_str receves NULL?
@onaecO
@onaecO Жыл бұрын
You mean smtg like my_printf(NULL);? Well this is a seg fault, indeed it's good practice always to check for NULL when dealing with pointers, in my simple implementation I just assumed no corner cases, like passing a NULL to a printf ^^ Anyway good question 👊🏻🔥
@oscarms6067
@oscarms6067 Жыл бұрын
Also if you pass a NULL as one of the variadic arguments to be processed as a string with print_string(). This function doesn't check it the pointer is NULL, before de dereferencing . Usually, in this case the constant string "(NULL)" is printed instead.
@onaecO
@onaecO Жыл бұрын
@@oscarms6067Yep! 100%, this is my mistake not properly handling NULLs and other corner cases, not pointing this out. I just wanted to show a boilerplate for a fully printf. I'll pin your comment for other ^^, ty for feedback!
@kwokhocheng-zf3fo
@kwokhocheng-zf3fo 4 ай бұрын
good
@a3y3g1
@a3y3g1 Жыл бұрын
As long as it norminettes
@onaecO
@onaecO Жыл бұрын
My friend, this is clearly not the real thing. is just a sample code
@a3y3g1
@a3y3g1 Жыл бұрын
Haha just messing with you absolutely amazing video. Your understanding is immaculate. Looking forward to watch the full printf if you drop the video. Not sure if you did already. Keep up the good work mate@@onaecO
@oneloveafrica8860
@oneloveafrica8860 10 ай бұрын
tanks
@swedishpsychopath8795
@swedishpsychopath8795 11 ай бұрын
I'm sorry - but your printf function won't work.
@onaecO
@onaecO 11 ай бұрын
I agree
@swedishpsychopath8795
@swedishpsychopath8795 11 ай бұрын
@@onaecO I'm just trolling. I'm sure it will work just fine! But you didn't get mad and didn't start to scream so I must find someone else to troll :)
@onaecO
@onaecO 11 ай бұрын
The "I don't give a f***k mode" must be always on when on internet 😂 Btw Happy new year my dear troll ♥️
@JohnSmith-g7e9x
@JohnSmith-g7e9x Жыл бұрын
If you can't even using C write printf, it means you are a loser in programing language.
@taleuback6799
@taleuback6799 9 ай бұрын
coucou ferme ta veste bisous
@PauloConstantino167
@PauloConstantino167 Жыл бұрын
hi there, my dream is to become a printf function
Let's build a printf! Episode n° 1 : Format parser
1:09:04
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
How Strong Is Tape?
00:24
Stokes Twins
Рет қаралды 96 МЛН
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
understanding ft_printf
11:23
nikito
Рет қаралды 15 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 94 М.
I built a real HTTP sever in ARM assembly in under 200 lines
22:34
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 335 М.
Reading and Writing Files in C, two ways (fopen vs. open)
7:07
Jacob Sorber
Рет қаралды 105 М.
Let's build a super simple shell
45:20
Oceano
Рет қаралды 2,3 М.
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.