4
wowotek
5y

Shower thoughts: i wondering something silly, for example address 0xf006 points to address 0xf003 which has value of 0x0000 how did it know if it is a 0 or a NULL

Comments
  • 11
    I think you've just realized that in low level languages in the end everything is just a bunch of bytes.
  • 1
    @gronostaj i learn x86 long time ago but i wondering how did the prog. lang. Know if it's a zero or a null.
  • 7
    @wowotek The same way that it knows if 0x61 is decimal 97 or letter "a": typing. You told it what type it is when declaring or assigning it.
  • 2
    @gronostaj ah so that why there is a static typing and dynamic typing. So in some point the prog lang just track the value so output what it expect?
  • 6
    @wowotek Yup. And in some languages, like C for example, you can abuse it and for example change "a" into "A" by subtracting 0x20.
  • 1
    @gronostaj ooo neat 🤣 never realized that thanks. But are you sure it was 0x20?

    Edit: yes its 0x20 it was a hex not decimal lmao
  • 3
    @wowotek yes its 0x20
  • 2
    @Codex404 yes i read it like a decimal 🤣
  • 0
    @Haxk20 wait linux use the RAM directly ?
  • 1
    It doesn't know whether 0x00 is zero or null without additional information
  • 0
    @12bitfloat that's my question
  • 1
    @wowotek Unix (and, by extension, Linux) expects the application programmer to be competent, and provides much less information as a system (because elegant simplicity and such).
  • 1
    @wowotek I can give you an example: Option in Rust (which either stores a value or nothing, null in a sense) stores an additional flag that tells it whether it has a value or not. (It really stores an enum discriminator because it's an enum, but same logic)
  • 2
    @Haxk20 my best C abuse was summing integers parallely on a single CPU process by treating a single 64 bit long pointer as two 32bit pointers. But adding it as longs. As long as you dont overflow it works, I benchmarked it and its 2x as fast, you can go further and sum 4 16-bit shorts and even 8 8-bit bytes... But with those overflows become more of a problem and additionall logic to prevent them eats up cycles
  • 0
    @FrodoSwaggins wait what? Omg i learn so much wtf 🤣🤣
Add Comment