Sponsored Content
Top Forums Programming C- static initialization of structures Post 302744955 by garysk on Sunday 16th of December 2012 01:58:41 AM
Old 12-16-2012
Don, a million thanks for your cogent reply.

'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:
Code:
NULL, '\0', '\0'

and the initializer:
Code:
'\0', '\0', '\0'

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.
 

10 More Discussions You Might Find Interesting

1. Programming

Struct Initialization

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)
Discussion started by: amatsaka
4 Replies

2. UNIX for Dummies Questions & Answers

Shell initialization files

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)
Discussion started by: SeanWuzHere
3 Replies

3. Programming

Char initialization

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)
Discussion started by: Nagapandi
2 Replies

4. IP Networking

I need HELP to Set up Coyote Linux router with 1 static IP & 64 internal static IP

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)
Discussion started by: dlwoaud
0 Replies

5. Shell Programming and Scripting

little confusion about variable initialization.

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)
Discussion started by: pinga123
9 Replies

6. Programming

Class Pointer initialization C++

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)
Discussion started by: mind@work
10 Replies

7. Programming

Even the Static cURL Library Isn't Static

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)
Discussion started by: BrandonShw
8 Replies

8. Shell Programming and Scripting

Initialization error

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)
Discussion started by: scriptor
12 Replies

9. Shell Programming and Scripting

Variable initialization

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)
Discussion started by: kekanap
9 Replies

10. Shell Programming and Scripting

Error occurred during initialization of VM

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)
Discussion started by: Kamal1108
2 Replies
CONFIG.GUESS(1) 						   User Commands						   CONFIG.GUESS(1)

NAME
config.guess - guess the build system triplet SYNOPSIS
config.guess [OPTION] DESCRIPTION
The GNU build system distinguishes three types of machines, the `build' machine on which the compilers are run, the `host' machine on which the package being built will run, and, exclusively when you build a compiler, assembler etc., the `target' machine, for which the compiler being built will produce code. This script will guess the type of the `build' machine. Output the configuration name of the system `config.guess' is run on. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit ENVIRONMENT VARIABLES
config.guess might need to compile and run C code, hence it needs a compiler for the `build' machine: use the environment variable `CC_FOR_BUILD' to specify the compiler for the build machine. If `CC_FOR_BUILD' is not specified, `CC' will be used. Be sure to specify `CC_FOR_BUILD' is `CC' is a cross-compiler to the `host' machine. CC_FOR_BUILD a native C compiler, defaults to `cc' CC a native C compiler, the previous variable is preferred REPORTING BUGS
Report bugs and patches to <config-patches@gnu.org>. Originally written by Per Bothner. Copyright 1992-2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
autoconf(1), automake(1), autoreconf(1), autoupdate(1), autoheader(1), autoscan(1), config.guess(1), config.sub(1), ifnames(1), libtool(1). GNU Autoconf 2.69 August 2017 CONFIG.GUESS(1)
All times are GMT -4. The time now is 06:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy