473,726 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is this a valid struct declaration

Hi All,
Is it valid:

struct test{

};

I mean, Can we have a struct containing no members? Is this a an
incomplete-type?

Please provide your expert comments.

Thanks,
Raman Chalotra
Jun 27 '08 #1
10 2240
On Jun 6, 2:32 pm, Raman <ramanchalo...@ gmail.comwrote:
Hi All,

Is it valid:

struct test{

};

I mean, Can we have a struct containing no members? Is this a an
incomplete-type?

Please provide your expert comments.

Thanks,
Raman Chalotra
I don't see anything wrong with the declaration. Though this stuff
does not look like it can have any practical applications.
The standard does not mandate declaring a member in a structure. This
code compiles with '-ansi' flag on Linux/gcc.
I don't see any reason why it should not be valid.
Jun 27 '08 #2
rahul <ra*********@gm ail.comwrites:
On Jun 6, 2:32 pm, Raman <ramanchalo...@ gmail.comwrote:
<snip>
>struct test{

};

I mean, Can we have a struct containing no members? Is this a an
incomplete-type?

Please provide your expert comments.

Thanks,
Raman Chalotra

I don't see anything wrong with the declaration. Though this stuff
does not look like it can have any practical applications.
The standard does not mandate declaring a member in a structure.
My copy does. The syntax specifies that there must be at least one
member. Where are you getting your information from?
This
code compiles with '-ansi' flag on Linux/gcc.
Add -pedantic.
I don't see any reason why it should not be valid.
--
Ben.
Jun 27 '08 #3
rahul wrote:
On Jun 6, 2:32 pm, Raman <ramanchalo...@ gmail.comwrote:
>Hi All,

Is it valid:

struct test{

};

I mean, Can we have a struct containing no members?
No.
>Is this a an
incomplete-type?
No.
>Please provide your expert comments.

Thanks,
Raman Chalotra

I don't see anything wrong with the declaration.
Then you need to look at the standard more carefully:
6.7.2.1 Structure and union specifiers
Syntax
1 struct-or-union-specifier:
struct-or-union identifieropt { struct-declaration-list }
struct-or-union identifier

struct-or-union:
struct
union

struct-declaration-list:
struct-declaration
struct-declaration-list struct-declaration

Note that a struct-declaration-list ALWAYS has a struct-declaration!
Though this stuff
does not look like it can have any practical applications.
The standard does not mandate declaring a member in a structure.
Wrong. From N1256:

This
code compiles with '-ansi' flag on Linux/gcc.
That does not make it procude all required diagnostics. You need '-ansi
-pedantic' at which point it gives a warning. Note that a warning is
sufficient to meet the standards requirement for "invalid" code (a puch
in the face could also qualify, but I don't think an implementation that
did this would be very popular)
I don't see any reason why it should not be valid.
See above.

An imcomplete type would be
struct test;
--
Flash Gordon
Jun 27 '08 #4
On Jun 6, 2:51*pm, rahul <rahulsin...@gm ail.comwrote:
On Jun 6, 2:32 pm, Raman <ramanchalo...@ gmail.comwrote:
Hi All,
Is it valid:
struct test{
};
I mean, Can we have a struct containing no members? Is this a an
incomplete-type?
Please provide your expert comments.
Thanks,
Raman Chalotra

I don't see anything wrong with the declaration. Though this stuff
does not look like it can have any practical applications.
The standard does not mandate declaring a member in a structure. This
code compiles with '-ansi' flag on Linux/gcc.
I don't see any reason why it should not be valid.
hey i dont find ne thng wrong in ur problem........ ..bt surely this
thng cannot b realised in practical situation...... rest its ok.tk cr
bye
Jun 27 '08 #5
On Fri, 6 Jun 2008 06:45:27 -0700 (PDT), muks <mu********@gma il.com>
wrote in comp.lang.c:
On Jun 6, 2:51*pm, rahul <rahulsin...@gm ail.comwrote:
On Jun 6, 2:32 pm, Raman <ramanchalo...@ gmail.comwrote:
Hi All,
Is it valid:
struct test{
};
I mean, Can we have a struct containing no members? Is this a an
incomplete-type?
Please provide your expert comments.
Thanks,
Raman Chalotra
I don't see anything wrong with the declaration. Though this stuff
does not look like it can have any practical applications.
The standard does not mandate declaring a member in a structure. This
code compiles with '-ansi' flag on Linux/gcc.
I don't see any reason why it should not be valid.

hey i dont find ne thng wrong in ur problem........ ..bt surely this
thng cannot b realised in practical situation...... rest its ok.tk cr
bye
hey ur a fkng mron.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jun 27 '08 #6

"muks" <mu********@gma il.comwrote in message
news:d9******** *************** ***********@a32 g2000prf.google groups.com...
[...]
hey i dont find ne thng wrong in ur problem........ ..bt surely this
thng cannot b realised in practical situation...... rest its ok.tk cr
bye
:^/

Jun 27 '08 #7
Dan
>hey i dont find ne thng wrong in ur problem........ ..bt surely this
thng cannot b realised in practical situation...... rest its ok.tk cr
bye
I have seen #defines that turn on and off structure members to save memory,
and one even turned all the members off.
Jun 27 '08 #8
rahul wrote:
On Jun 6, 2:32 pm, Raman <ramanchalo...@ gmail.comwrote:
>Hi All,

Is it valid:

struct test{

};

I mean, Can we have a struct containing no members? Is this a an
incomplete-type?

Please provide your expert comments.

Thanks,
Raman Chalotra

I don't see anything wrong with the declaration. Though this stuff
does not look like it can have any practical applications.
The standard does not mandate declaring a member in a structure. This
code compiles with '-ansi' flag on Linux/gcc.
I don't see any reason why it should not be valid.
Are you sure you weren't compiling as C++?

--
Ian Collins.
Jun 27 '08 #9
On Jun 6, 4:56 pm, Flash Gordon <s...@flash-gordon.me.ukwro te:
rahul wrote:
On Jun 6, 2:32 pm, Raman <ramanchalo...@ gmail.comwrote:
Hi All,
Is it valid:
struct test{
};
I mean, Can we have a struct containing no members?

No.
Is this a an
incomplete-type?

No.
Please provide your expert comments.
Thanks,
Raman Chalotra
I don't see anything wrong with the declaration.

Then you need to look at the standard more carefully:
6.7.2.1 Structure and union specifiers
Syntax
1 struct-or-union-specifier:
struct-or-union identifieropt { struct-declaration-list }
struct-or-union identifier

struct-or-union:
struct
union

struct-declaration-list:
struct-declaration
struct-declaration-list struct-declaration

Note that a struct-declaration-list ALWAYS has a struct-declaration!
Though this stuff
does not look like it can have any practical applications.
The standard does not mandate declaring a member in a structure.

Wrong. From N1256:
This
code compiles with '-ansi' flag on Linux/gcc.

That does not make it procude all required diagnostics. You need '-ansi
-pedantic' at which point it gives a warning. Note that a warning is
sufficient to meet the standards requirement for "invalid" code (a puch
in the face could also qualify, but I don't think an implementation that
did this would be very popular)
I don't see any reason why it should not be valid.

See above.

An imcomplete type would be
struct test;
--
Flash Gordon
HI,

Yes, and
1. we cant apply sizeof to incomplete types.
2. what if we create array of this struct(incomple te), every element
having same mem address....whic h is probably violation of array
concept in itself.

Thanks,
Raman Chalotra
Jun 27 '08 #10

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

Similar topics

5
1548
by: Gianni Mariani | last post by:
The 3 compilers I tried all did different things. gcc 3.4.0 ICE's (Bug 15480) MS C++ 7.1 has meaningless diags Comeau accepts the code Obviously this is not somthing I'll be using until we get the compilers doing the right thing, but I do want to report the appropriate errors. BTW, I think the code is valid. It does the thing I was trying to do
4
2475
by: Dan | last post by:
I'm trying to creat a data structure, that can be either a integer, double, string, or linked list. So I created the following, but don't know if it is the data structure itself causing problems, or something I am doing in the rest of the program. This is the data structure. struct node { char type;
19
2632
by: Russell Shaw | last post by:
Hi, I have two structs in a header file, and they reference each other, causing a compile error. Is there a standard way to deal with this? typedef struct { ... RtAction *actions; } RtWidget;
2
1722
by: Martijn van Buul | last post by:
Hi, Today, I stumbled over the following: I had a struct, whose scope only made sense within a single function, and I wanted to use std::swap() on it, like the following example: #include <algorithm> void somefunction()
14
2303
by: Lane Straatman | last post by:
I would like to write a 'struct'. I have a library that is all but completely inappropriate for this task. So I'm looking for C code that fills in the gaps between: #undef whateverkeithsaysfor99compliance #define whateverkeithsays for99compliance int main(void { struct foo
2
4700
by: Laurent Deniau | last post by:
I would like to know why the following small program does not compile (checked with gcc 4.1.2) and if the compiler behavior is correct: struct A; typedef void (T)(struct A*); void f(void) { struct A { int _; } a; ((T*)0)(&a);
5
322
by: Boris | last post by:
Is this a valid C++ program (according to the C++ standard)? I ask as I'm trying to port a Windows library to Solaris, and the Solaris C++ compiler reports an error (The name x is ambiguous in ns1: ns2::x and ns1::x). The code below reproduces the problem, and I wonder now if I have to adapt the code or submit a bug report to Sun? namespace ns1 { struct x { }; }
2
281
by: beet | last post by:
Hi all, I tried to declare a c++ struct like following in a header file; I want to include this header file in other files to create and access this struct. ------ 1 #ifndef _SEARCHDATA_H_ 2 #define _SEARCHDATA_H_ 3
4
1861
by: rn | last post by:
the code below compiles OK with gcc 4.0 but not with gcc.4.2 and visual studio 2005 (ver 8 ). to me it seems it should not compile. ----- class test1 { public:
0
8890
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
8752
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
9402
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9259
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
9120
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
8101
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
4521
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
4785
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2639
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.