473,890 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with typedef


Hi All,

I'm a bit confused by the following which is causing one of
our user's codes fail in compilation:

typedef struct SctpDest_S;

1) Is this standard ?
2) If so ( or even if not so ! ) what is it supposed to do ?

The error message is

"A typedef declaration must declare a name."

which seems to make sense ! Sorry if I missing the obvious
but it's not related to 1.17 in the FAQ, is it ?

On similar grounds he has typedefs of the form

typedef struct SctpHeartbeatCh unk_S
{
SctpChunkHdr_S sHdr;
u_short usInfoType;
u_short usInfoLength;
double dTimestamp;
SctpDest_S *spDest;
};

Again is this standard and what is it supposed to do ? ( though this time
I might be able to guess )

Sorry if this is obvious, looking in K&R2 I can't find it and C is very much
my second language (I'm a Fortran guy),
Ian

Jun 29 '06 #1
15 2583
Ian Bush wrote:
I'm a bit confused by the following which is causing one of
our user's codes fail in compilation:

typedef struct SctpDest_S;

1) Is this standard ?
2) If so ( or even if not so ! ) what is it supposed to do ?

The error message is

"A typedef declaration must declare a name."

which seems to make sense ! Sorry if I missing the obvious
but it's not related to 1.17 in the FAQ, is it ?
A typedef creates a new name (I call it a "synonym") for an existing
type, so you need to provide two names, the old and the new.

You are giving only one: SctpDest_S

It should be either

typedef struct SctpDest_S new_name;

or

typedef struct old_name SctpDest_S;
On similar grounds he has typedefs of the form

typedef struct SctpHeartbeatCh unk_S
{
SctpChunkHdr_S sHdr;
u_short usInfoType;
u_short usInfoLength;
double dTimestamp;
SctpDest_S *spDest;
};

Again is this standard and what is it supposed to do ? ( though this time
I might be able to guess )

Sorry if this is obvious, looking in K&R2 I can't find it and C is very much
my second language (I'm a Fortran guy),

Jun 29 '06 #2
Roberto Waltman wrote:
Ian Bush wrote:
I'm a bit confused by the following which is causing one of
our user's codes fail in compilation:

typedef struct SctpDest_S;

1) Is this standard ?
2) If so ( or even if not so ! ) what is it supposed to do ?

The error message is

"A typedef declaration must declare a name."

which seems to make sense ! Sorry if I missing the obvious
but it's not related to 1.17 in the FAQ, is it ?


A typedef creates a new name (I call it a "synonym") for an existing
type, so you need to provide two names, the old and the new.

You are giving only one: SctpDest_S

It should be either

typedef struct SctpDest_S new_name;

or

typedef struct old_name SctpDest_S;


Yes, I understand this. However my user has not and I am wondering if under
any circumstances it may mean anything, and if so what are those circumstances
and what does it mean ?

Thanks,

Ian

Jun 29 '06 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Roberto Waltman wrote:
Ian Bush wrote:
I'm a bit confused by the following which is causing one of
our user's codes fail in compilation:

typedef struct SctpDest_S;

1) Is this standard ?
2) If so ( or even if not so ! ) what is it supposed to do ?

The error message is

"A typedef declaration must declare a name."

which seems to make sense ! Sorry if I missing the obvious
but it's not related to 1.17 in the FAQ, is it ?
A typedef creates a new name (I call it a "synonym") for an existing
type, so you need to provide two names, the old and the new.


ITYM
"so you need to provide a type and a name".
You are giving only one: SctpDest_S
ITYM
"You are giving only the name"
It should be either

typedef struct SctpDest_S new_name;
which contains a type "struct SctpDest_S" and a name "new_name"
or

typedef struct old_name SctpDest_S;


which contains a type "struct old_name" and a name "SctpDest_S "
On similar grounds he has typedefs of the form

typedef struct SctpHeartbeatCh unk_S
{
SctpChunkHdr_S sHdr;
u_short usInfoType;
u_short usInfoLength;
double dTimestamp;
SctpDest_S *spDest;
};
which has a type of "struct SctpHeartbeatCh unk_S { ... }" but no name.
Again is this standard and what is it supposed to do ? ( though this time
I might be able to guess )
AFAIK, this isn't standard, and it should not compile. It is an
incomplete typedef, lacking a name to be typedef'ed to the given type.
Sorry if this is obvious, looking in K&R2 I can't find it and C is very much
my second language (I'm a Fortran guy),

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32) - WinPT 0.11.12

iD8DBQFEo9yTagV FX4UWr64RAqwOAK CuTRe2TSQZHqXbB k23LvVLR29+ngCf VS4a
WGlbAVDN0yOfTGv 3SjRgOrs=
=AL4R
-----END PGP SIGNATURE-----

Jun 29 '06 #4
Ian Bush wrote:
Hi All,

I'm a bit confused by the following which is causing one of
our user's codes fail in compilation:

typedef struct SctpDest_S;

1) Is this standard ?
2) If so ( or even if not so ! ) what is it supposed to do ?

The error message is

"A typedef declaration must declare a name."

which seems to make sense ! Sorry if I missing the obvious
but it's not related to 1.17 in the FAQ, is it ?

On similar grounds he has typedefs of the form

typedef struct SctpHeartbeatCh unk_S
{
SctpChunkHdr_S sHdr;
u_short usInfoType;
u_short usInfoLength;
double dTimestamp;
SctpDest_S *spDest;
};

Again is this standard and what is it supposed to do ? ( though this time
I might be able to guess )


typedef requires a type and a name that will become a synonym for that
type. In the first example "struct SctpDest_S" is the type, in the
second example the entire struct definition is the type. In both cases
the name is missing so neither of them are valid C constructs.

Robert Gamble

Jun 29 '06 #5
Ian Bush wrote:
Roberto Waltman wrote:
It should be either
typedef struct SctpDest_S new_name;
or
typedef struct old_name SctpDest_S;
Yes, I understand this. However my user has not and I am wondering if under
any circumstances it may mean anything,


I don't think so. If you didn't read it already, see Lew Pitcher's
corrections to my post.
and if so what are those circumstances
and what does it mean ?


A shot in the dark: If you know that code "worked" somewhere, could it
be that is was produced by a tool, or run through the C preprocessor,
and a missing definition is being substituted by an empty string?
Jun 29 '06 #6


Ian Bush wrote On 06/29/06 11:01,:
Roberto Waltman wrote:

Ian Bush wrote:
I'm a bit confused by the following which is causing one of
our user's codes fail in compilation:

typedef struct SctpDest_S;

1) Is this standard ?
2) If so ( or even if not so ! ) what is it supposed to do ?

The error message is

"A typedef declaration must declare a name."

which seems to make sense ! Sorry if I missing the obvious
but it's not related to 1.17 in the FAQ, is it ?


A typedef creates a new name (I call it a "synonym") for an existing
type, so you need to provide two names, the old and the new.

You are giving only one: SctpDest_S

It should be either

typedef struct SctpDest_S new_name;

or

typedef struct old_name SctpDest_S;

Yes, I understand this. However my user has not and I am wondering if under
any circumstances it may mean anything, and if so what are those circumstances
and what does it mean ?


Others have explained that the declaration is wrong,
but your problem seems to be convincing your user of its
wrongness. Perhaps if you ask him to ponder

typedef int;

.... he'll begin to come around.

--
Er*********@sun .com

Jun 29 '06 #7
Ian Bush wrote:
Hi All,

I'm a bit confused by the following which is causing one of
our user's codes fail in compilation:

typedef struct SctpDest_S;

1) Is this standard ?
2) If so ( or even if not so ! ) what is it supposed to do ?

The error message is

"A typedef declaration must declare a name."

which seems to make sense ! Sorry if I missing the obvious
but it's not related to 1.17 in the FAQ, is it ?

On similar grounds he has typedefs of the form

typedef struct SctpHeartbeatCh unk_S
{
SctpChunkHdr_S sHdr;
u_short usInfoType;
u_short usInfoLength;
double dTimestamp;
SctpDest_S *spDest;
};

Again is this standard and what is it supposed to do ? ( though this time
I might be able to guess )

Sorry if this is obvious, looking in K&R2 I can't find it and C is very much
my second language (I'm a Fortran guy),
Ian


Try:

typedef struct SctpHeartbeatCh unk_S
{

SctpChunkHdr_S sHdr;
u_short usInfoType;
u_short usInfoLength;
double dTimestamp;
SctpDest_S *spDest;

} SctpHeartbeatCh unk_S;
Jun 29 '06 #8
Ian Bush wrote:
Hi All,

I'm a bit confused by the following which is causing one of
our user's codes fail in compilation:

typedef struct SctpDest_S;

(in addition to the other replies)
grep through the code and see if he ever uses SctpDest_S
like this:
SctpDest_S variable_name;

as opposed to this:
struct SctpDest_S variable_name;

If he does, then I'm guessing (which is always a bad idea but
unavoidable sometimes to the maintainer) that he *may* have
meant:
typedef struct SctpDest_S SctpDest_S;

<snipped>

hth
goose

Jun 29 '06 #9
Ian Bush wrote:

Hi All,

I'm a bit confused by the following which is causing one of
our user's codes fail in compilation:

typedef struct SctpDest_S;

1) Is this standard ?
No.
The procedure, or a procedure,
for writing a typedef is
first you write something that looks exactly like
an object definition or a function definition.

int My_def;

Then you write typedef in front of it.

typedef int My_def;
The only way that

struct SctpDest_S;

could be an object definition,
would be if SctpDest_S was some kind of funky macro.
On similar grounds he has typedefs of the form

typedef struct SctpHeartbeatCh unk_S
{
SctpChunkHdr_S sHdr;
u_short usInfoType;
u_short usInfoLength;
double dTimestamp;
SctpDest_S *spDest;
};


Same problem.

This way would be OK,
as long as all the member types are defined:

typedef struct {
SctpChunkHdr_S sHdr;
u_short usInfoType;
u_short usInfoLength;
double dTimestamp;
SctpDest_S *spDest;
} SctpHeartbeatCh unk_S;

--
pete
Jun 29 '06 #10

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

Similar topics

17
6554
by: Axel | last post by:
Hiho, here my Newbie question (Win32 GUI): I'm reading a file in binary mode to a char* named buffer. I used malloc(filesize) to make the needed space avaiable. The filedata in the buffer seems to be ok..I can write the variable buffer back to a file and the contents is ok. So I think until here all goes fine... But now I want write the buffer contents to a Memo-Box for displaying.
14
2118
by: Dave | last post by:
Hello all, Can anybody help with the problem below? I'm trying to define a conversion function that converts objects to function pointers and am getting a compile error on the line indicated below. The compiler interprets this is a function returning a function, which, of course is illegal... What is the correct syntax to accomplish this? Thanks, Dave
1
1885
by: Antti Granqvist | last post by:
Hello! I have following object relations: Competition 1--* Category 1--* Course 1 | | * Course
5
1891
by: jose luis fernandez diaz | last post by:
Hi, When I compiling the program below: #include <map> using namespace std; template<typename td1, typename td2, typename td3,typename td4> class Tarificador
12
1722
by: Franz | last post by:
Greetings, I have created the following types: typedef struct _tbl_certificate{ int cert_id; char *cert_name; }tbl_certificate; typedef struct _cameraObj{ tbl_camera camera;
16
3853
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
23
5842
by: myth.drannon | last post by:
lets say I have a header file : struct AAAA { blabla..... }; typedef struct AAAA A; typedef struct BBB
2
3286
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs thru. But once i add more, it dies. In this program i have 4 files setup to read. The
10
1892
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle using the * character. The program was just for practice but I am having problems. My main problem is, in my program I use 4 functions to change or access two variables in my code. The variables are
0
10819
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
10923
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
10462
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
9633
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
8016
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
5851
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
6045
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4676
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
3
3277
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.