473,804 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

incorrect warning?

When I compile the program below "Program start" with
gcc -std=c99 -pedantic -o bgcc bgcc.c
(where gcc --version gives
gcc (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2)
Copyright (C) 2004 Free Software Foundation, Inc.
)
I get the warning
bgcc.c:3: warning: "struct thingTag" declared inside parameter list
bgcc.c:3: warning: its scope is only this definition or declaration, which
is probably not what you want

Should the code generate a warning? Is there a way to avoid it other than
adding
typedef struct thingTag * thingP;
and replacing line 3 with
typedef void (*show)( thingP);
(which does shut gcc up)?

TIA
Duncan

Program start
#include <stdio.h>

typedef void (*show)( struct thingTag *);

typedef struct thingTag
{ show f;
double v;
} thing;

void show_metres( thing* p)
{ printf( "%f m\n", p->v);
}

int main( int argc, char** argv)
{
thing T;
T.v = 1.7;
T.f = show_metres;
T.f( &T);
return 1;
}
Jun 20 '06
10 2108
In article <pa************ *************** *@this.address>
Duncan Muirhead <no***@this.add ress> wrote:
If I understand [Keith Thompson] correctly, there is a special rule
for declarations of function (pointer) types ...
Not exactly. See the article I already referred you to elsewhere in
this thread.
As for typedefs for struct types, I suspect your right, but would say:
I, and indeed the people I've worked with, only ever use the typedef'd
names in code and so having the two names is limited to the type
declaration.


In that case, use the method I outlined in that same article.

Note that you can use the *same* name for the typedef-name and
the structure tag:

struct Foo;
typedef struct Foo Foo;

Note also that you can write "struct Foo;" (at file scope) as many
times as you like, while you can only have the typedef line once.
Hence, in some (relatively rare) situations, you *must* use only
the tag. For instance, if zog.h declares a prototype for a function
zog() that operates on a "Zog", while glik.h declares a prototype
for a function glik() that happens to take a "Zog" as an argument
but -- for whatever reason -- glik.h cannot #include "zog.h" nor
require that those who include glik.h also include zog.h first,
then glik.h must use "struct Zog" instead of "Zog:

/* glik.h */
struct Zog;
void glik(struct Zog *);

/* zog.h */
struct Zog;
typedef struct Zog Zog;

void zog(Zog *);

struct Zog {
Zog *next;
... other fields ...
};

(Of course, everything becomes much simpler if you just throw away
the typedef, and type out the word "struct". Then you no longer
need some sort of typographic gimmick -- in this case, the initial
capital letter -- to distinguish typedef-identifiers from other
ordinary identifiers. Not that a *compiler* needs such a gimmick,
but if you do not use one, programmers will make more mistakes.)
--
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.
Jun 23 '06 #11

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

Similar topics

2
8234
by: Steven D'Aprano | last post by:
I'm trying to keep an open mind, but I am perplexed about something in Python that strikes me as a poor design. py> def func(a,b): py> print a,b py> func(1) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: func() takes exactly 2 arguments (1 given)
5
5615
by: GitarJake | last post by:
Hello all, Newbie here. SQL 2000, Windows 2000 I'm trying to alter tables in my SQL DB using statements like the following: /* AD_GROUPS */ alter table AD_GROUPS alter column AD_GROUP_NAME nvarchar(64)not null go
0
1068
by: Dilip | last post by:
Vaclav I have taken the liberty to cross-post this microsoft.public.dotnet.languages.vc which has more visibility from MSFT VC++ team. thanks --Dilip Actual post by Vaclav Haisman originally posted at
9
2068
by: Brad | last post by:
I have written some code to manipulate data/records in a MASTER (order header) and DETAIL (order details) tables. What I have written is too extensive to post but essentially trying to: 1. Assign to a datarow (dr1) the first record of the MASTER table 2. Assign to another datarow (dr2) the second record of the MASTER table 3. If dr1.field1 = dr2.field1, then proceed, otherwise do stop 4. Assign to a third datarow (dr3) the first record...
4
2761
by: Peter Ritchie | last post by:
Does anyone know how to suppress a specific warning for a line or block of code in C#? C++ has a nice facility to disable a warning for a block of code with #pragma for warnings that are incorrect or don't apply. For example, the following code generates an CS0628 because CS0628 makes an incorrect assumption that "protected" applies only to inheritance: public sealed class Class { EmbeddedClass utility = new EmbeddedClass();
18
3929
by: Sven | last post by:
Hi, I found a strange behaviour when using the time() function from time.h. Sometimes when it is called, it does not show the correct time in seconds, but an initial value. This time seem to be the time when the program was started the first time. My platform is a DEC machine with Tru64 onboard. A possible explanation could be, that the time() function is called
3
3301
by: Don Burden | last post by:
We've started converting some applications to the .NET 2.0 framework. When compiling in VS 2005, I'm getting a warning on this line: return (unitWidth != null ) ? unitWidth : new Unit("0px"); Looks valid to me, but this gives a warning with "new" underlined saying "warning CS0429: Unreachable expression code detected".
0
5372
by: torpecool | last post by:
Hello Everyone, I have been trying to find information about this issue in the documentation and have not been able to. I hope someone can help. I built a web-based app (PHP) that allows users to upload the contents of a CSV file into database tables. My users have reported that most of the time, everything is fine, but some records do not show up. Although I can see the records by doing
6
2399
by: kepston | last post by:
Hi I have a report which splits invoice costs to various departments and shows a summary. The various divisors and multipliers used in deriving the values for each department, are such that the final figures will not be to 2 decimal places. I decided to use the Round() function so that the calculated figure would equal the formatted figure. I then Summed the rounded figures to reach a total. Occasionally the sum will not equal the actual...
0
9714
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
9594
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
10350
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...
0
10096
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
9174
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
7638
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
5534
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...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.