Special usage of NULL

xiaoxiao2021-03-06  51

The compiler can check out the following While loop missed a semicolon:

/ * Memcpy Copy a non-overlapping memory block * /

Void * Memcpy (void * pvto, void * pvfrom, size_t size)

{

BYTE * PBTO = (Byte *) PVTO;

BYTE * PBFROM = (byte *) pvfrom;

WHILE (size -> 0);

* PBTO = * PBFROM ;

Return (PVTO);

}

We can know that the semicolue after the While expression is definitely a mistake after the indentation of the program, but the compilation

The order is considered to be a completely legitimate While statement, its cyclic body is an empty statement. Since there is sometimes empty statements, there is

No empty statements are required, so in order to find unwanted empty statements, compilers are often given a novel statement.

Optional warning information, automatic warnings you may have the above error. When you are determined when you need a nicker, you will use it. but

It is best to use NULL to make it obvious. E.g:

Char * STRCPY (Char * PCHTO, Char * PCHFROM)

{

Char * pchstart = PCHTO;

While (* PCHTO = * PCHFROM )

NULL;

Return (PCHSTART);

}

Since NULL is a legitimate C expression, this program has no interprises. More benefit using NULL is

The compiler does not generate any code for the NULL statement because NULL is just a constant. In this way, the compiler is accepted

Explicit NULL statement, but automatically uses an implicit empty statement as an error.

转载请注明原文地址:https://www.9cbs.com/read-81912.html

New Post(0)