473,769 Members | 5,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"extern struct foobar" linux compilation warning

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 struct foobar;
^

This is apparently a forward reference to a data structure
for the purposes of declaring a pointer to this opaque
structure.

Any ideas how to get rid of this warning???

Thanks in advance!
Rick
Nov 14 '05
10 3518
In article <ba************ ****@tematic.co m>
Kevin Bracey <ke**********@t ematic.com> wrote:
... [using] a typedef hides the fact the handle is a struct from the
basic API. One might want (for whatever reason) to change the handle
from an int to a structure or vice-versa.


Sure -- but then one could just define a struct containing a single
"int".

Always just use "struct"; it is C's way of defining abstract data
types. :-)

I am "only almost kidding" about "always", too. Note that using a
struct to hold a single scalar variable gives you type-safety:

struct temperature { double val; };
struct pressure { double val; };

Now it is impossible to accidentally pass a "temperatur e" to a
function requiring a "pressure". You can add a typedef if you
really want:

#ifdef USE_TYPEDEFS
typedef struct temperature Temperature;
typedef struct pressure Pressure;
typedef struct counter Counter;
#endif

struct temperature; /* opaque */
struct pressure; /* opaque */
struct counter { int val; }; /* exposed */

If you make the handle an int, you are stuck. If you make it a
typedef and make the typedef an int and someone uses an int, you
are *still* stuck:

/* remove previous typedef and struct */
typedef int Counter;

extern Counter add(Counter previous, int offset);
...
/* bad programmer, using int instead of the typeef-name: */
void f(void) {
int x;
...
x = add(x, 3); /* this code compiles just fine */
...
}

but if you use a struct -- whether opaque or exposed -- even the
bad programmer has to use the name you gave it:

/* put back typedef and struct */

/* bad programmer attempts to use int instead of the typedef-name: */
void f(void) {
int x;
...
x = add(x, 3); /* error: function add() requires a
struct counter and returns a struct counter,
so this code does not compile */
...
}

Of course, if you always use struct, the typedef is unnecessary. Just
think of the word "struct" as meaning "type":

#define type struct

type foo; /* declare type foo to exist */
type bar; /* declare type bar to exist */

static type foo x = FOO_INITIALIZER ; /* make x a foo */
extern type bar y; /* declare y as a bar, defined elsewhere */

and you have a language with an obvious user-defined abstract data
type mechanism. Take out the single "#define" and you still have
that language -- it is called "C". :-) (Of course, to get everything
to work right, you need C99 with its compound-literals.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #11

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

Similar topics

3
1969
by: Christopher M. Lusardi | last post by:
Hello, THE PROBLEM ----------- If I compile parts of my program with CC, and C, using extern "C" as appropriate it compiles without any errors, but it does a segmentation fault when I run the program. The variables involved in the segmentation fault are surrounded by compiler directives. I am 100% sure that I do not have to extern "C"
22
6030
by: Ian | last post by:
The title says it all. I can see the case where a function is to be called directly from C, the name mangling will stuff this up. But I can't see a reason why a template function can't be given extern "C" linkage where it is to be assigned to a C function pointer. Ian
9
8256
by: tropostropos | last post by:
On Solaris, using the Sun compiler, I get annoying warnings from the following code. The problem is that I am passing a C++ member function pointer to the C library function qsort. Is there a solution? Declaring the function extern "C" fails, because linkage declarations must be made at file scope. #include <stdlib.h> //for qsort template <class T> class Sorter
11
9427
by: Daniele Benegiamo | last post by:
Is the following program standard-compliant? I've compiled it with some compilers and no errors or warnings are produced, but this is not a demonstration. The "incriminated" part is the declaration: extern "C" struct X; that is then defined as:
10
6196
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: // main.cpp // This is defined in a C module extern "C" void fake_qsort(void*, std::size_t, std::size_t, int (*compare)(const void*, const void*));
0
1163
by: Lei Jiang | last post by:
I have setup a .NET library in C++ language in VS.NET 2005 Beta1. I this project, I add some additional dependency to some C library. The header file of the C library has been marked as "extern "C"", but the linker just can't find these function entries. After I read the error report carefully, I found that the compiler seems ignored these "extern C" mark. The linker report : Error 13 error LNK2020: unresolved token (0A00001A) "void...
4
4758
by: kk_oop | last post by:
Hi. I need to write a C++ callback function and register it with a C program. I've read that this can be done if the callback function is a static method. I've also read that I should use a global function with the extern "C" prefix. I was leaning toward using the static method approach until I saw a posting that said compatibility between static C++ functions and C is not guaranteed in the respective language standards. This made me...
5
1937
by: jchludzinski | last post by:
I have 3 files (see below: a.h, w.c, ww.c). I would like to use a single x (declared somewhere) which would global to both compilation units: w.c & ww.c. No matter where I place the "extern" qualifier - it appears to work: x is shared between w.c and ww.c. Or if I simple don't use "extern", it works. Why? What is the correct (or simply preferred) usage? ---John PSI'm using gcc (GCC) 4.0.2.
13
2091
by: arnuld | last post by:
this is the code: ------------------------------------------------------------------------- #include <iostream> #include <string> #include <vector> struct Pair { std::string name;
0
9589
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
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9866
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
8876
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...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
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
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.