'Pon our systems, NULL the pointer is defined as (void *)0. NUL the character is (char)0. This is why I have been saying, as you do below, it would be natural to expect a warning about the type coercion implied by my mistake.
But, as I also said at the thread head, zero is zero is zero. And C is enamored with zeros, for breakfast lunch and dinner, where more strongly typed languages would never allow such digital promiscuity.
Our OS is 32-bit kernel running on a 64-bit architecture; we tell the compiler so by using the -march=1.0 which means PA RISC 1 architecture, a 32 bit system. Our int's long's and pointers are all 32-bit. We are stuck in the 32bit timewarp as untangling all the 32-bit words and coding each properly for 64 bits in a 720k-line package where pointer/integer cross-overs are rampant, as are exchanges between longs and ints. It has been judged a monumental rewrite that is not in the current budget. Fortunately, our package compiles links and runs (same gcc version, whatever that means cross-architectures) on RedHat 64-bit (kernel 2.6.18), so we can presumably limp along indefinitely on an antedeluvian setup, as long as gcc supports us.
There is a loss of bts in the compiler's conversion (bits that are always 0). But coercing a 32-bit pointer to fit into an 8-bit char is potentially a little lossy.
Quote:
Originally Posted by Don Cragun
I agree with what Jim McNamara has already said. I hope this may provide a little more that will help explain what you're seeing.
Depending on the programming environment you're using, NULL is likely to be defined to be 0, 0L, or (void *)0. (All three of these are used for one or more of the multiple programming environments provided by OS X and all three of these are legitimate values for NULL according to the C Standard depending on the relative sizes of pointers and integers in your programming environment.)
If NULL expands to 0 in your programming environment, there would be absolutely no difference to the compiler between the initializer:
and the initializer:
If NULL expands to 0 or 0L, no pointer to integer conversion is needed to turn NULL into an integer constant used to initialize the array of characters in your structure.
I agree that if your compilation environment has NULL defined to be (void *)0 it would have been nice for the compiler to produce a warning, but I don't see anything in the C Standard that would require that to happen since the conversion from a NULL pointer to an integer constant expression is a well defined operation with no loss of data involved.
Hi
We are using a code generator for initializing structures with the #define macro. Compiling it with the GCC 2.8.1 (with -ansi) it OK. But when we are using the SUN C 5.0 compiler it screams.
Following is a code sample:
#include <stdlib.h>
#include <stdio.h>
typedef struct TEST3 {... (4 Replies)
As you know, when a user logs in, the shell reads the initialization files in an order something like below...
###################
Bourne Shell
/etc/profile > $HOME/.profile
Bash Shell
/etc/profile > $HOME/.bash_profile > $HOME/.bash_login > $HOME/.profile > $HOME/.bashrc
C Shell... (3 Replies)
Hi All,
char a="\0";
a) a contains \0
a contains garbage value
b) a contains \
a contains 0
a contains garbage value
Pls, let me know correct result is a or b. I guess a.
Thanks,
Naga:cool: (2 Replies)
hello, i need help on setting my coyote linux, i've working on this for last 5 days, can't get it to work. I've been posting this message to coyote forum, and other linux forum, but haven't get any answer yet. Hope someone here can help me...... please see my attached picture first.
... (0 Replies)
Whenever i execute the below scriptlet with out proper file name it deletes /tmp directory .
I guess this is because value of variable a didnt get initialized and there for rm -rf /tmp/ get executed and entire /tmp directory get deleted.
How would i avoid any empty variables to be used in... (9 Replies)
Hello everyone,
I have a question, that are the following ways of pointer intialization same ?
ClassA *point;
point = 0;
point = new ClassA;
Thanks a load in advance!!
Regards, (10 Replies)
I'm writing a program which uses curl to be run on Linux PCs which will be used by a number of different users. I cannot make the users all install curl on their individual machines, so I have tried to link curl in statically, rather than using libcurl.so. I downloaded the source and created a... (8 Replies)
new to shell scripting.
below line is showing error in script.
${parameter:=word}
in the o/p first it shows the below error.
word: not found.
and then in next line print "word"
----------------
p2: word: not found.
word
---------------------------
OS is AIX and shell is... (12 Replies)
Hallo Team,
I have a simple request and i would appreciate your help.
I would like to use two dates in my script lets:
A=$(date +"%d %B %Y")
echo $A
23 June 2014
That's awesome now we cooking. Now i want B to be on the previous month
eg: echo $B Should give me
23 May 2014
I would... (9 Replies)
Hi ,
I was invoking a sh file using the nohup command. But while invoking, I received a below error.
Error occurred during initialization of VM
Unable to load native library: /u01/libjava.so: cannot open shared object file: No such file or directory
.
Could you please help out.
Regards,... (2 Replies)