Advertising (This ad goes away for registered users. You can Login or Register)

The Official Programming Dictionary

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
hgoel0974
Retired Mod
Posts: 2155
Joined: Mon Jul 23, 2012 11:42 pm
Location: New York

Re: The Official Programming Dictionary

Post by hgoel0974 »

BTW, according to wikipedia, the definitions vary based on the context, null character is a zero valued ASCII character
null pointer is pointer pointing to an undefined space etc

http://en.wikipedia.org/wiki/Null
Advertising
"If the truth is a cruel mistress, then a lie must be a nice girl"
Acid_Snake
Retired Mod
Posts: 3100
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: The Official Programming Dictionary

Post by Acid_Snake »

hgoel0974 wrote:null pointer is pointer pointing to an undefined space etc
that's funny cause that's not what that link you provided says, it rather makes a difference between a NULL pointer and an uninitialized pointer, which is what you just described.
Advertising
hgoel0974
Retired Mod
Posts: 2155
Joined: Mon Jul 23, 2012 11:42 pm
Location: New York

Re: The Official Programming Dictionary

Post by hgoel0974 »

Acid_Snake wrote:
hgoel0974 wrote:null pointer is pointer pointing to an undefined space etc
that's funny cause that's not what that link you provided says, it rather makes a difference between a NULL pointer and an uninitialized pointer, which is what you just described.
well :oops: my bad, that's what I thought I read but anyway, technically a null pointer points to 0, right?
"If the truth is a cruel mistress, then a lie must be a nice girl"
codestation
Big Beholder
Posts: 1660
Joined: Wed Jan 19, 2011 3:45 pm
Location: /dev/negi

Re: The Official Programming Dictionary

Post by codestation »

Depends on the implementation. In some obscure platforms null isn't zero and the address at 0 is a valid address.

The important thing is that neither C or C++ has tied NULL to 0 (as physical address).
Plugin list
Working on: QPSNProxy, QCMA - Open source content manager for the PS Vita
Playing: Error: ENOTIME
Repositories: github, google code
Just feel the code..
Acid_Snake
Retired Mod
Posts: 3100
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: The Official Programming Dictionary

Post by Acid_Snake »

codestation wrote:Depends on the implementation. In some obscure platforms null isn't zero and the address at 0 is a valid address.

The important thing is that neither C or C++ has tied NULL to 0 (as physical address).
The way I see it is that NULL means it's not pointing to anything (hence the name), while void is undefined, it could be pointing to a valid (albait random) area or it could be some other random thing which could cause a crash or malfunction, this is why we always initialize pointers to NULL, to prevent this random behaviour.
It is true that some machines may define 0 as a valid address, we can build computers however we want, but the way Null is defined in language and maths makes it 0. A NULL-terminated string ends with 0, not a random, undefined number.
codestation
Big Beholder
Posts: 1660
Joined: Wed Jan 19, 2011 3:45 pm
Location: /dev/negi

Re: The Official Programming Dictionary

Post by codestation »

For strings is different since one uses a nul character instead of a NULL pointer.

Also, i cannot remember the source but i read that internally the C compiler will replace 0 with the internal representation of the NULL pointer for that platform when is assigned to a pointer type. So in some cases

Code: Select all

int *foo = 0;
Is the same as:

Code: Select all

int *foo = NULL;
But in neither case the memory contents of foo are guaranteed to be 0 in all their bits (this is platform dependant). Let me see if i can find the source of that.

BTW, this thread is now about NULL :lol:
Plugin list
Working on: QPSNProxy, QCMA - Open source content manager for the PS Vita
Playing: Error: ENOTIME
Repositories: github, google code
Just feel the code..
Acid_Snake
Retired Mod
Posts: 3100
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: The Official Programming Dictionary

Post by Acid_Snake »

codestation wrote:Also, i cannot remember the source but i read that internally the C compiler will replace 0 with the internal representation of the NULL pointer for that platform when is assigned to a pointer type
I think it's in sdtio or stdlib, you have something like this

Code: Select all

#ifdef GCC
#define NULL 0x0
#else
#define NULL 0
#endif
ot something like that, I don't know it by heart but you can find that
codestation wrote:For strings is different since one uses a nul character instead of a NULL pointer.
there's no such thing as a null character, internally what you place at the end of a string is 0x00, which is not as different as NULL being 0x0
svenn
Posts: 65
Joined: Fri Dec 24, 2010 5:17 pm
Location: Belgium
Contact:

Re: The Official Programming Dictionary

Post by svenn »

Acid_Snake wrote:You are looking at this definition from a high level perspective, which is ALWAYS the wrong way to look at computers, or every other mathematical or physical form. As I explained before, in semantics, mathematics AND computing, NULL == 0, I don't care what Javascript tells you, JavaScript is high level, so it separates itself from everything related to what a computer really is and gives you a false feeling of what a computer is and how it works. To give you a better view of why JavaScript's Null can't really be considered "null" in itself, take a look at python's version of Null and how it really works at low level, you will then see that JavaScript's Null != the mathematical, semantc and computing definition of Null.
This is getting weird; but the topic title is "programming dictionary", not computer dictionary, I have no idea, and honestly no need to know how 0 or NULL is being stored in C or Python; But In my opinion, stating that NULL = 0, is wrong;

Simply because, it might suggest that this code is valid, and broadly accepted :
i = NULL;
i++;
i = 3+NULL;

And since this is a topic for new people they might think this is also valid :
i = NULL + ONE + SEVEN;
And unless you have constants defined, would not work.

Though, I'm stuck in the mindset that NULL should not mean the same thing as 0; So there is no point arguing.
Acid_Snake
Retired Mod
Posts: 3100
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: The Official Programming Dictionary

Post by Acid_Snake »

svenn wrote:unless you have constants defined, would not work.
I'm gonna revert you to what I previously said:
Acid_Snake wrote:I think it's in sdtio or stdlib, you have something like this

Code: Select all

    #ifdef GCC
    #define NULL 0x0
    #else
    #define NULL 0
    #endif

ot something like that
point being that NULL == 0, but some compilers parse stuff like "int i = NULL + 1" to make them invalid, still you should at least do some research before posting, NULL == 0, both in semantics, maths and programming.
codestation
Big Beholder
Posts: 1660
Joined: Wed Jan 19, 2011 3:45 pm
Location: /dev/negi

Re: The Official Programming Dictionary

Post by codestation »

In the end, it really matters? In C/C++, NULL is defined in a header so the preprocessor replaces it.

Original source code:

Code: Select all

#include <stdio.h>
int main() {
    int *foo = NULL;
    int *bar = 0;
    printf("Hello wololo\n");
    return 0;
}
gcc -E test.c

Code: Select all

...
int main() {
    int *foo = ((void *)0);
    int *bar = 0;
    printf("Hello wololo\n");
    return 0;
}
g++ -E test.cpp

Code: Select all

...
int main() {
    int *foo = __null;
    int *bar = 0;
    printf("Hello wololo\n");
    return 0;
}
Then the compiler sees that there is an zero assigment (in C) or a __null one (int C++) to a pointer type and replaces that zero for the platform dependant null value (zero in 99% of the use cases).
Plugin list
Working on: QPSNProxy, QCMA - Open source content manager for the PS Vita
Playing: Error: ENOTIME
Repositories: github, google code
Just feel the code..
Locked

Return to “Programming and Security”