Replacing printf

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024
  • Replacing printf.

ความคิดเห็น • 40

  • @deftlyhacked3494
    @deftlyhacked3494 7 ปีที่แล้ว +7

    +Jonathan_Blow, C actually does let you use your own buffers for files using the setvbuf function. The line-based buffering for FILEs with a default buffer size of BUFSIZ is just a convenience.

  • @tceffect2353
    @tceffect2353 4 ปีที่แล้ว +13

    The signed integer code has a bug. If you pass in a -2^63 you will get an error. It will see that it is a signed int, print out the minus sign, and then multiply -2^63 by -1. You will end up with 2^63 in a signed int which has a maximum value of 2^63-1, which is an overflow. I have had to implement an int to string function for a system where I didn't have the standard library, and that was a bug I had.

    • @sqlexp
      @sqlexp 7 หลายเดือนก่อน

      Once the value is in an unsigned integer variable, it doesn't matter.

  • @izerpizer
    @izerpizer 7 ปีที่แล้ว +11

    He writes code faster than I can speak.

  • @ocaly
    @ocaly ปีที่แล้ว +1

    Recursion also is able prints unsigned decimal/hex numbers without buffer. Since it reverses the output and that's exactly what you want with numbers when using mod (% in c).

  • @GingerGames
    @GingerGames 9 ปีที่แล้ว +5

    Type casting seems to be a little inconsistent. I know this is syntaxual (if that's a word) but because variables are declared like this:
    `name : type = ...`
    It makes much more sense to cast with the type afterwards.
    Current casting:
    `cast(type) var`
    Consistent casting:
    `var as type`
    `cast(var, type)`
    Then auto-casting can a little simpler to read:
    `var as auto_symbol`
    `cast(var)`
    `cast(var, auto_symbol)`
    `autocast(var)`
    Again this is not that important yet but consistency and readability is good.

  • @dietermuller4345
    @dietermuller4345 9 ปีที่แล้ว +2

    in the linux terminal you can use the emacs shortcuts as well ! (in my case fedora)

  • @masterofIich
    @masterofIich 4 ปีที่แล้ว +2

    "I guess it will just work". I never guess i guess.

  • @luckylove72
    @luckylove72 4 ปีที่แล้ว +1

    Hope this is about MS implementation of printf.

  • @schavery
    @schavery 9 ปีที่แล้ว +7

    Why is printf one of the worst C functions?

    • @Scy
      @Scy 9 ปีที่แล้ว +11

      steven avery because the formatting rules are designed by 1970s unix programmers with too much free time and no concept of user friendlyness.

    • @knik3
      @knik3 9 ปีที่แล้ว +3

      steven avery IMO one of the best.

    • @GabrielHasbun
      @GabrielHasbun 9 ปีที่แล้ว +3

      steven avery It isn't.

    • @Scy
      @Scy 9 ปีที่แล้ว +1

      Gabriel Hasbun It is. If you watch part 2 and 3 you'll understand why. Internationalization.

    • @GabrielHasbun
      @GabrielHasbun 9 ปีที่แล้ว

      Oh. True.

  • @not_herobrine3752
    @not_herobrine3752 6 หลายเดือนก่อน

    I should write myself a language that transpiles to c for fun someday

  • @shitheadjohnson2797
    @shitheadjohnson2797 2 ปีที่แล้ว

    printf is the wildcard standard IO function in stdio, can have infinite parametra, i could never work it out. :) is wierd trying to make a version of it.

  • @Xeab
    @Xeab 4 ปีที่แล้ว +1

    1 being successful would confuse me to no end

  • @sadmac7000
    @sadmac7000 9 ปีที่แล้ว +16

    You've implemented a curious type system. Basically Any is a boxed type where the language takes care of the boxing but not the unboxing. That seems like a mistake to me. It feels like you've partially hacked in higher-level type awareness into a language that doesn't have it.
    Look at what something like Ceylon does here instead.

    • @jblow888
      @jblow888  9 ปีที่แล้ว +6

      sadmac7000 Sigh.

    • @sadmac7000
      @sadmac7000 9 ปีที่แล้ว +1

      Timothy Schmid Necessary in what sense? Vacuously we could all write in assembly language.

    • @sadmac7000
      @sadmac7000 9 ปีที่แล้ว +2

      Well right, but, none of it is necessary. Language design is a desirability game not a necessity game.

    • @sadmac7000
      @sadmac7000 9 ปีที่แล้ว +2

      Timothy Schmid the point is union typing and putting all this type_info crap behind some macros or operators makes the code strictly easier to read, is zero-cost (yes, really zero cost. It's a compile-time feature) and doesn't expose the guts of the programming language to the user (we want to interface with the hardware on a low level. Not the damn linker tables).

    • @sadmac7000
      @sadmac7000 9 ปีที่แล้ว +1

      Timothy Schmid but it's not necessary for the language :P
      I kid I kid.

  • @lukaszmatecki4218
    @lukaszmatecki4218 8 ปีที่แล้ว +4

    You are going to rewrite printf() during one hour of programming? This is ambitious :)

  • @dinunclv
    @dinunclv 7 ปีที่แล้ว +1

    I wrote a program, that is building tetris figures into the smallest square they possibly fit in. I did not know that printf is so stupid, so I was using it a lot for checks. First I generate a map, I display it using printf, then I build the figures and display it again, if I delete the first printf(that displays the empty map, the program does not work any more)! can someone give me a tip?

  • @Eugensson
    @Eugensson 8 ปีที่แล้ว +2

    You use "*cast(^Type) variable" too often, why wouldn't you implement another keyword for it eg "as_ref(Type) variable"?

    • @kynikersolon3882
      @kynikersolon3882 4 ปีที่แล้ว +6

      Bad trade off sparing a trivial amount of writing by implementing something that makes the language harder to learn.

    • @AlFredo-sx2yy
      @AlFredo-sx2yy ปีที่แล้ว

      thats because he's passing pointers just through the address, which is what you'd understand as passing parameters as a void* in C or C++ and then casting them back to the type he wants them to be when using them and dereferences them.. So why should he add this "as_ref"? What he's doing is just fine and it is understandable. as_ref would actually make it harder to understand what is going on, because in my mind it makes it seem like i'd be return a pointer or reference of some sort, while ^ is the pointer symbol here, so... i would not be getting what the name you proposed implies.

  • @jupiterapollo4985
    @jupiterapollo4985 9 ปีที่แล้ว +2

    Second

  • @Dengakuman22
    @Dengakuman22 9 ปีที่แล้ว +2

    Fourth

  • @ishdx9374
    @ishdx9374 3 ปีที่แล้ว +1

    Thirtythird

  • @Technolgy2
    @Technolgy2 7 ปีที่แล้ว +1

    Twentieth

  • @guidoretro
    @guidoretro 9 ปีที่แล้ว +2

    +301st

  • @stefeegb
    @stefeegb 9 ปีที่แล้ว +2

    Fifth

  • @michalstrba5928
    @michalstrba5928 9 ปีที่แล้ว +2

    Sixth