473,761 Members | 6,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

not computable at load time?

What is wrong with the following code? My compiler (GCC) produces a warning
which states that the initialisation values of a local struct are "not
computable at load time". A warning is not equal to an error, but it usually
suggests that the code is at least questionable. I do not see anything
questionable...

This program demonstrates the issue. I get the warning whenever I pass a
pointer to a structure and use the fields of that structure to initalise the
values of a local structure. What is not kosher about that?

===

typedef struct {
int *ab;
int *ac;
} TEST;

typedef struct {
int *b;
int *c;
} TESTO;

void testo(TEST *aba)
{
/* warning - not computable at load time? */
TESTO kd = {aba->ab, aba->ac};
}
int main(void)
{
TEST aba;

testo(&aba);
return 0;
}
OK, the fields of aba are not initalised in this demo code, but that does
not matter. The warning shows up even if all fields of the passed structure
contain valid values.
Jul 31 '07 #1
2 2515
On Wed, 1 Aug 2007 00:32:18 +0200, "copx" <co**@gazeta.pl wrote in
comp.lang.c:
What is wrong with the following code? My compiler (GCC) produces a warning
which states that the initialisation values of a local struct are "not
computable at load time". A warning is not equal to an error, but it usually
suggests that the code is at least questionable. I do not see anything
questionable...

This program demonstrates the issue. I get the warning whenever I pass a
pointer to a structure and use the fields of that structure to initalise the
values of a local structure. What is not kosher about that?

===

typedef struct {
int *ab;
int *ac;
} TEST;

typedef struct {
int *b;
int *c;
} TESTO;

void testo(TEST *aba)
{
/* warning - not computable at load time? */
TESTO kd = {aba->ab, aba->ac};
}
int main(void)
{
TEST aba;

testo(&aba);
return 0;
}
OK, the fields of aba are not initalised in this demo code, but that does
not matter. The warning shows up even if all fields of the passed structure
contain valid values.
All versions of the C standard prior to 1999 required that
initializers for an automatic aggregate (structure or array) must be
constant expressions.

In C, the value of an object, even a const object, is NEVER a constant
expression. Some compilers (quite a few, actually) accept this as an
extension. All the gcc is doing is warning you that it is accepting
this code as an extension, that it is not standard C, and it might not
be portable to other compilers that don't provide the same extension.

From 1999 on, this rule was changed in the C standard, and the code
you have written is valid in any compiler that conforms to the 1999 or
later version of the C standard. Depending on how old your version of
gcc is, you might be able to invoke it in C99 conforming mode, in
which case the warning should disappear.

But then the code still might no be portable to other compilers that
conform to C99.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Aug 1 '07 #2

"Jack Klein" <ja*******@spam cop.netschrieb im Newsbeitrag
news:mm******** *************** *********@4ax.c om...
On Wed, 1 Aug 2007 00:32:18 +0200, "copx" <co**@gazeta.pl wrote in
comp.lang.c:
>What is wrong with the following code? My compiler (GCC) produces a
warning
which states that the initialisation values of a local struct are "not
computable at load time". A warning is not equal to an error, but it
usually
suggests that the code is at least questionable. I do not see anything
questionable.. .

This program demonstrates the issue. I get the warning whenever I pass a
pointer to a structure and use the fields of that structure to initalise
the
values of a local structure. What is not kosher about that?

===

typedef struct {
int *ab;
int *ac;
} TEST;

typedef struct {
int *b;
int *c;
} TESTO;

void testo(TEST *aba)
{
/* warning - not computable at load time? */
TESTO kd = {aba->ab, aba->ac};
}
int main(void)
{
TEST aba;

testo(&aba);
return 0;
}
OK, the fields of aba are not initalised in this demo code, but that does
not matter. The warning shows up even if all fields of the passed
structure
contain valid values.

All versions of the C standard prior to 1999 required that
initializers for an automatic aggregate (structure or array) must be
constant expressions.

In C, the value of an object, even a const object, is NEVER a constant
expression. Some compilers (quite a few, actually) accept this as an
extension. All the gcc is doing is warning you that it is accepting
this code as an extension, that it is not standard C, and it might not
be portable to other compilers that don't provide the same extension.

From 1999 on, this rule was changed in the C standard, and the code
you have written is valid in any compiler that conforms to the 1999 or
later version of the C standard. Depending on how old your version of
gcc is, you might be able to invoke it in C99 conforming mode, in
which case the warning should disappear.
I see. Thanks!

[snip]

Aug 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
6699
by: B. Wood | last post by:
I have a small program (see below) that demonstrates an error I am getting when I build the program on a linux platform. I first initialize an unsigned char array (lines 16). I then initialize my array of my typedeffed structure (dataStruct) (lines 18-24). I use my initialized unsigned character array to initialize the unsigned character pointer member of the structure (line 21).
6
16986
by: Clint Olsen | last post by:
What about the following is not computable? It seems that the size of foo is easily computable: typedef struct { char *name; char *data; } Foo; int main(void) {
4
4119
by: bingfeng | last post by:
I have some codes generated by perl, in which initialize some huge struct,such as PARA TOS_network_spantree_set_0_para_0 = { "vlan", emNUM, NULL, "", "configuration on a designated vlan", PRO_REQUIRED }; const char* TOS_network_spantree_set_0_para_1_emvalue = { "disable", "enable", NULL }; PARA TOS_network_spantree_set_0_para_1 = { "", emENUM, TOS_network_spantree_set_0_para_1_emvalue, "", "enable or disable STP", PRO_REQUIRED };
12
6190
by: Sharon | last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at http://www.codeproject.com/bitmap/graphicsuite.asp). I also wrote a small console application in C++ (unmanaged) that uses the DLL above. Now the application, together with the above DLL’s is successfully loading a TIF image file (62992 x 113386 Pixels, Huffman RLE compression, 3200 x 3200 DPI resolution, binary colored (1 Bit Per Pixel), file on disk size 43.08...
11
2364
by: Jason | last post by:
Hi I have a "problem" i have got a ASP.NET application. in this application i have included logging. in the logging i have logged how many seconds it takes for this application to fully load. i have placed these timing loggings in the Load and Init events on a typical aspx page. i.e. first line of code in Page_Load is DateTime dtStart = DateTime.Now; and the last lines of code are
2
2023
by: **Developer** | last post by:
I have a Form (FV&C) containing a userconrtrol (CF&E) I do a ShowDialog for the form and the form's Load calls a method of the UserControl. The first time I do this the usercontrol appears on the form as I'd expect after the method had been run. The second time I do this the usercontrol appears on the form as if the usercontrols Load had last been run.
4
2211
by: Ravi Ambros Wallau | last post by:
Hi: We developed a set of ASP.NET Web Applications that never runs in stand-alone mode, but always inside a portal (Rainbow Portal). All modules are copied on that portal. My question is: load time takes, sometimes, three or four of minutes in a medium-level machine (a PIII 1.5 Ghz), when the binary contents are changed, or if the time of last modification of the web.config file is changed. An application that runs in "stand-alone" mode...
19
2287
by: natG | last post by:
On a warehouse app, our Java clients constantly load/insert rows into the db. I would like to throttle these inserts (1.5 million rows per hr) from the Java app, based on current 'busy state' of the server. It would be nice if I can get the server CPU utilization (and other key factors) from db2 via jdbc. However, it needs to be low cost, since it would likely run every x seconds. System: db2 v 9.1 64bit on Centos 4.3 64 bit. Thank...
5
4120
by: Med | last post by:
Hi, Initial load of my pre-compiled ASP.NET app takes more than 50 seconds to load after site has been idle for a while. Then it become fairly fast. Followings are my app/hardware configs: Server/IIS: ----------- IIS 6 running on Hosted VPS Windows 2003 Enterprise, with allocated 512MB
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9957
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9775
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8780
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7332
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3881
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 we have to send another system

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.