473,507 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

i want to ask about NULL

1 New Member
what is the function of NULL. can some one explain it to me about this:=
srand (time(NULL));
Jul 17 '14 #1
4 1251
donbock
2,426 Recognized Expert Top Contributor
NULL is a macro (defined in <stddef.h> and elsewhere). It is the implementation-defined null pointer constant. A pointer with this value is understood to not point at anything. Conversely, a pointer with any other value can be assumed to point to something.

null has no special technical meaning. It has the standard dictionary meaning.

NUL is the name of the ASCII null character. The character code for NUL is 0, which coincidentally is the value of the null character in C ('\0'). The null character is used to terminate strings.

Refer to the manpage for time to see what that function does when its argument is NULL.
Refer to the manpage for srand to see what that function does with the value passed to it.
Jul 17 '14 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Since NULL has no special meaning it is often used as a zero.

Anytime you use NULL and expect it to be zero, you are coding a potential bug since your code may not work on some compilers.

Defensive coding practice would ask that you use 0 for zero rather than use NULL.
Jul 17 '14 #3
donbock
2,426 Recognized Expert Top Contributor
Hmmm. Maybe I'm wrong about not using NULL for function pointers. Refer to C FAQ 5.8.

NULL is the null pointer value for data pointers. The C Standard permits compiler implementations to use different encoding rules for data pointers and function pointers if that makes sense for the particular environment. Portable code does not assign data pointer values to function pointers or vice-versa. Thus, portable code will not assign NULL to function pointers. The portable null pointer value for function pointers is the bare integer 0. I have been known to use the following private macro for the null function pointer constant:
Expand|Select|Wrap|Line Numbers
  1. #define FNULL 0
By the way, the "%p" format code for printf is for data pointers. I can't think of a maximally portable way to print out the value of a function pointer.
Jul 17 '14 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
There you are. FNULL for function pointers and NULL for data pointers. I can say that in the 25 years I have been around C/C++ code, I have never seen FNULL.

I am not believer in macros because the preprocessor may not expand them in the way I expect and the compiler has no way to verify the expansion is correct.

Personally, I hard-code a 0 in both cases. That, to me, is a null value.
Jul 17 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
42382
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
12
1757
by: D Witherspoon | last post by:
What is the accepted method of creating a data class or business rules object class with properties that will allow the returning of null values? For example... I have a class named CResults with...
102
5904
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
3
7302
by: Rodrigo C. Souza | last post by:
I need to insert a null value in a table on MS SQL Server 2000 using a stored procedure. When I send no data to the stored procedure, I get an error saying that the value cannot be null, but I did...
5
1699
by: Christoffer Gurell | last post by:
I want to create a program which displays large tables and makes this possible over a slow connection. The problem is that when i do a PQexec the entire retultset is transfered. I would like to...
12
4115
by: Miles Keaton | last post by:
PG peeps: What's the prevailing wisdom & best-practice advice about when to let a varchar (or any) column be NULL, and when to make it NOT NULL DEFAULT '' (or '0000-00-00' or whatever) - in...
17
4494
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
2
19557
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
5
7255
by: hello | last post by:
How can I define the schema so that myage element has to be double or null? <xs:simpleType name="myage"> <xs:restriction base="xs:double"> <xs:enumeration value="null"/> </xs:restriction>...
4
11772
by: oh4real | last post by:
Hello all, I am very new to coding and even newer to Javascript. My brain works by thinking in general/abstract all the time and I am lazy, so I hate doing anything remotely repetitious. In that...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.