Hi,
Like fundamental data types (int,char,float,...),why can't we are
not able to make userdefined datatypes as extern.
if "file1.C" conatains
struct a
{
int x;
} b = { 3 };
and in "file2.C" if I want to access b.x, by making
extern struct a b;
the compiler will flash error.
Thanks
Bangalore. :lol: 5 22842
> Hi, Like fundamental data types (int,char,float,...),why can't we are not able to make userdefined datatypes as extern.
if "file1.C" conatains struct a { int x; } b = { 3 };
and in "file2.C" if I want to access b.x, by making extern struct a b; the compiler will flash error.
The problem here is that in file2.c, the compiler does not know what
"struct a" is. For this, it must be able to see its definition. Try
this...
// file.h
struct A
{
int x;
};
// file1.cpp
#include "file.h"
A obj = {3}; // struct keyword not required here! its C++
// file2.cpp
#include "file.h"
extern A obj; // defined elsewhere
Now you can compile file1.cpp and file2.cpp seperately and link them
together.
HTH
Regards,
Srini
Bangalore wrote: Hi, Like fundamental data types (int,char,float,...),why can't we are not able to make userdefined datatypes as extern.
if "file1.C" conatains struct a { int x; } b = { 3 };
and in "file2.C" if I want to access b.x, by making extern struct a b; the compiler will flash error.
That's because the compiler only know that there is a struct called 'a'. It
doesn't know anything else about it, like that it has a member called 'x'.
So the compiler cannot use it without seeing the whole definition of the
struct.
hello, what you could do is declare a pointer of type struct and then use
that.
"maadhuu" <ma************@yahoo.com> wrote in message
news:b6******************************@localhost.ta lkaboutprogramming.com... hello, what you could do is declare a pointer of type struct and then use that.
Eh? What's a "pointer of type struct"? And how would a pointer solve the
problem that the compiler can't see his struct definition (since the struct
definition is in a file which is not #include'd)?
-Howard
> Hi, Like fundamental data types (int,char,float,...),why can't we are not able to make userdefined datatypes as extern.
if "file1.C" conatains struct a { int x; } b = { 3 };
and in "file2.C" if I want to access b.x, by making extern struct a b; the compiler will flash error.
The problem here is that in file2.c, the compiler does not know what
"struct a" is. For this, it must be able to see its definition. Try
this...
// file.h
struct A
{
int x;
};
// file1.cpp
#include "file.h"
A obj = {3}; // struct keyword not required here! its C++
// file2.cpp
#include "file.h"
extern A obj; // defined elsewhere
Now you can compile file1.cpp and file2.cpp seperately and link them
together.
HTH
Regards,
Srini This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gernot Frisch |
last post by:
Problem:
A.cpp:
------
static FOO* gFoo=NULL;
A.h
extern FOO* gFoo;
gives: L2001 - unresolved external: "symbol struct FOO* gFoo"
|
by: Dan Elliott |
last post by:
Hello,
Converting from a working C program to C++, I run into the following error:
I have a header: (header.h)
namespace shared{
...
struct X{
...
|
by: atv |
last post by:
Alright, i have some questions concerning include files en global
variables.I hope someone is willing to answer these.
1).Why is it that if i define a global variable in a file, say main.c,
and...
|
by: Rick Anderson |
last post by:
All,
I am receiving the following compilation error on LINUX
(but not Solaris, HPUX, WIN32, etc):
compiling osr.c
LBFO.h(369): warning #64: declaration does not declare anything
extern...
|
by: Tapeesh |
last post by:
I would like to know what is the expected behaviour of C compilers when
an extern decleration is intialized.
When the following code is compiled using gcc
//File extern.c
int arr ;
int a ;
|
by: Steffen Loringer |
last post by:
Hi all,
I can't figure out why a can't use my struct TestStructure in other
files. Any ideas? My project consists of
main.c,lib1.h,lib1.c,lib2.c,lib2.h .
main.c...
|
by: Martin Jørgensen |
last post by:
Hi,
Problem:
========
Some of my output functions are beginning to take pretty many
arguments... I mean.... We're talking about 10-15 arguments :-)
So I thought to myself, perhaps this is...
|
by: Lalatendu Das |
last post by:
I have seen a header file in which one structure is defined with
extern declaration in a header file and declared one variable of that
structure in one C-file. The code goes as mentioned below . I...
|
by: CptDondo |
last post by:
I've got a question on the proper handling of sizeof.
I have two files; a.c and b.c
In b.c I have:
struct Key en_keys = {
{EN_ENTER, DELAY, NULL},
};
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |