Newbie Array Problem - how to strncpy fr 
Author Message
 Newbie Array Problem - how to strncpy fr


 >>     I thought NULL was just a constant zero, not implicitly or
 >> explicitly a pointer value. Correct me if I am wrong, if I make below
 >> statements {...}

They will, but the preferred method is to use NULL for pointers and 'real' zero
for variables.  There were a couple of compilers at one time that had NULL
equal to -1 (I think ... but then again ...)

---------------------------------------------------------------------
 Scott J. Walter, Prod. Dev.          | "Ah'm sorrah, sir ... but y'
                                      |  jes kinna fit annah muhr on
 Maverick Software                    |  th' floppy.  Y' jes kinna
 9801 Dupont Avenue South, #205       |  mess wi' th' lahws o' data
 Bloomington, MN  55431               |  compression!"

---------------------------------------------------------------------
  "It's not a bug ... it's not a feature ... it's an ENHANCEMENT!!"



Sat, 15 Mar 1997 10:09:16 GMT  
 Newbie Array Problem - how to strncpy fr

Quote:

> >>     I thought NULL was just a constant zero, not implicitly or
> >> explicitly a pointer value.

NULL (not necessarily the macro by the same name) is a pointer.  Any use
of a constant 'zero' in a pointer context must generate a NULL pointer.
Because of this, some implementations define NULL as '0', when they
should more properly use '(void *)0'.  The latter definition aids the
compiler in generating appropriate warning messages.  Still, while a
zero generates a NULL, it is not advisable to assume that NULL will
generate a zero.

Quote:
>They will

*May*, not will.  (Although they usually will).

Quote:
>There were a couple of compilers at one time that had NULL
>equal to -1 (I think ... but then again ...)

NULL is always represented as (some kind of) constant 0.  The actual bit
pattern for a NULL need not be all zeroes, and both all ones and some
other patterns are used on various machines.

--
#include        <standard.disclaimer>
 _
Kevin D Quitt  USA 91351-4454           96.37% of all statistics are made up



Sun, 16 Mar 1997 00:12:59 GMT  
 Newbie Array Problem - how to strncpy fr


Quote:

> >>     I thought NULL was just a constant zero, not implicitly or
> >> explicitly a pointer value. Correct me if I am wrong, if I make below
> >> statements {...}

>They will, but the preferred method is to use NULL for pointers and 'real' zero
>for variables.

As Arjan correctly states NULL is allowed to be defined in the headers as
((void *) 0). in general the result of converting this quantity back to an
arithmentic type is undefined.

Quote:
>There were a couple of compilers at one time that had NULL
>equal to -1 (I think ... but then again ...)

NULL has always been 0 or 0 converted to a suitable type as far as source
code goes. A compiler is allowed to use any value it likes to represent
NULL behind the scenes but it has to perform suitable conversions so that
no ANSI conforming (its difficult to specify the required limitations
on non-ANSI) code can tell this.

--
-----------------------------------------


-----------------------------------------



Sun, 16 Mar 1997 04:16:00 GMT  
 Newbie Array Problem - how to strncpy fr


Quote:
>Because of this, some implementations define NULL as '0', when they
>should more properly use '(void *)0'.

Strictly it is just as proper to define NULL as 0 as to define it as
((void *) 0), however code should never make any assumptions about which it
is.

Quote:
>The latter definition aids the
>compiler in generating appropriate warning messages.

In a few situations but I don't believe it makes much difference in
practice.

Quote:
> Still, while a
>zero generates a NULL, it is not advisable to assume that NULL will
>generate a zero.

Indeed it is quite wrong to do so.

--
-----------------------------------------


-----------------------------------------



Wed, 19 Mar 1997 08:24:31 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Newbie Array Problem - how to strncpy from an array of char

2. Thread Q fr. newbie

3. strncpy/strncpy

4. another newbie question: strncpy function

5. Problem with strncpy

6. strcat() and strncpy() problem - help!

7. Problem with strncpy

8. Problem with strncpy

9. Problem with strncpy!!!

10. Read file to array problem (Newbie for those wishing to avoid)

11. newbie char array assignment problem

12. Newbie problem with arrays

 

 
Powered by phpBB® Forum Software