473,327 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Structure Compatibility


I have the following question:

1. According to 6.2.7P1 of Std, are the
following structures compatible?

(Assume you compile with proper options)

/* compatible.c */
#include <stdio.h>

struct A
{
int a;
char b;
};

int
main ( void )
{
struct A a = { 5, 'a' };
extern struct A b;
b = a;
printf ( "%d %c\n", b.a, b.b );
return 0;
}

/* compatible2.c */
struct A
{
int a;
char b;
};

Thanks
Nov 13 '05 #1
2 1208
"Vijay Kumar R Zanvar" <vi***********@globaledgesoft.com> wrote in
news:bp*************@ID-203837.news.uni-berlin.de:

I have the following question:

1. According to 6.2.7P1 of Std, are the
following structures compatible?

(Assume you compile with proper options)

/* compatible.c */
#include <stdio.h>

struct A
{
int a;
char b;
};

int
main ( void )
{
struct A a = { 5, 'a' };
extern struct A b;
Wouldn't this be a name space colision? I don't understand your use of
"compatible".
b = a;
printf ( "%d %c\n", b.a, b.b );
return 0;
}

/* compatible2.c */
struct A
{
int a;
char b;
};

Thanks


--
- Mark ->
--
Nov 13 '05 #2
On Fri, 14 Nov 2003 15:32:17 +0530, Vijay Kumar R Zanvar wrote:
/* compatible.c */
#include <stdio.h>

struct A
{
int a;
char b;
};

int
main ( void )
{
struct A a = { 5, 'a' };
extern struct A b;


This means "declare b as a variable with external linkage of type
struct A". The struct A being referred to here is the struct A at
the beginning of file compatible.c

What you are specifying with the storage class specifier here is
that b is not a local variable in main. You are telling the
compiler to use some other b. Since there is no "other" b
defined in this code, it won't compile.

In the Standard, 6.2.2 says:
4 For an identifier declared with the storage-class specifier
extern ... If no prior declaration is visible ... then the
identifier has external linkage.
Nov 13 '05 #3

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

Similar topics

0
by: Ahmad | last post by:
Dear all, I'm not sure if this is the write newsgroup, but ... I've been trying to update the web-site for the local orphanage (www.bedaya.org.my) via FP2002. This whole project started on...
3
by: pramod | last post by:
Two differenet applications (running on different OS, different compilers) are communicating thru protocol consisting of functions and arguments. Communication link can be TCP/IP, or serial port....
15
by: damian birchler | last post by:
Hi I'm wondering of what type a structure is. Of course, it is a _structure_, but an array isn't an _array_ either. So of what type is a structure? I'd say a pointer, am I right?
14
by: frostalicious | last post by:
Used VB.NET (on my client PC) to convert VB6 executable to .NET executable. Placed the .exe file on a network drive on my server. From client, ran .NET Wizards "Trust an Assembly" to make the...
4
by: Scott Lemen | last post by:
Hi, Some Win APIs expect a structure with a fixed length string. How is it defined in VB .Net 2003? When I try to use the FixedLengthString class I get an "Array bounds cannot appear in type...
1
by: tony.fountaine | last post by:
I am working on a project to read a Bosch Measurement Data File (MDF). The file contains a number of blocks that can be read from the file using a baisc structure. For example the ID BLOCK is as...
28
by: kyle york | last post by:
Greetings, Why does the C standard require the members of a structure not be re-ordered (6.2.5.20)? Padding is allowed, and platform dependent, which means one cannot rely on the exact layout...
6
by: Scoots | last post by:
I know the usually applied workaround for multiple definitions of header files, but I have a problem on this one. This time, I can't just ifndef the header file that defines my structure. So...
56
by: Bruce. | last post by:
I would like to allocate a structure size of 1024 bytes but I want the compiler to do the calculation for me. typedef struct { int var1; int var2; int var3; char ...
6
by: Mohamed Fysal | last post by:
Hi, I have a major problem. I am using a VB exe which is having a structure declared and it looks like below Public Type SCANNEDIBUTTNO IButtonUserNumber As String * 32
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.