Author Topic: NULLs in High-Level languages  (Read 17454 times)

Offline hhh3h

  • Jr. Member
  • *
  • Posts: 41
NULLs in High-Level languages
« on: January 26, 2011, 04:20:30 PM »
Greetings. I was wondering if anyone could help me to understand how the concept of a null value relates to assembly.

Many high-level languages have the concept of null, but i was wondering how that translates into assembly.

I'm not an assembly programmer, but I was just interested in the concept.  Thanks.

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: NULLs in High-Level languages
« Reply #1 on: January 27, 2011, 09:33:23 AM »
In assembly, we treat NULL the same as zero, it's for clarity to let the developer know that the argument was supposed to be a pointer of some kind but it's being ignored. This comes from (afaik) early C code which referred to NULL as a "void pointer to zero" or "#define NULL ((void*)0)", however this convention didn't actually survive to be cross platform because many compiler developers felt the same way about it as assembly developers do and some compilers now define NULL as "#define NULL 0". In fact, I think that C++ now forces the NULL = 0 convention and many C++ compilers will refuse to even build the ((void*)0) variants (causing a lot of problems when cross building C and C++). Personally, I would say just treat it as 0 but only use it where pointers are expected to be used.

About Bryant Keller
bkeller@about.me

Offline hhh3h

  • Jr. Member
  • *
  • Posts: 41
Re: NULLs in High-Level languages
« Reply #2 on: January 27, 2011, 05:33:36 PM »
That's very informative.  I appreciate your reply.