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

Home Posts Topics Members FAQ

Do I need the C-style struct instantiation in C++ at all?

Hi,

I'm using a glibc system header <sys/stat.h> which defines a C struct
'stat'. Furthermore, I'm using the struct 'dirent', defined in <dirent.h>.

Now, at one point in my code I'm holding an std::list of dirents:

std::list< dirent > mylist;

This works.

Now, I wanted to extend the list to hold pairs of dirent/stat:

std::list< std::pair< dirent, stat > > mynewlist;

Now, the compiler (g++ 3.3.4) says he doesn't know a type called 'stat'. So
I tried the C-style notation for instantiating structs:

std::list< std::pair< dirent, struct stat > > mynewlist;

This works. I find it rather odd that I can pass 'dirent' without a
preceding 'struct', but for 'stat' I have to do it the C way to calm the
compiler.

So, is there a rule of thumb in which cases I need the C-notation? Frankly I
was quite sure that you don't need it at all in C++.

Thanks in advance,
Matthias
Jul 22 '05 #1
3 1684
Matthias Käppler wrote:
Hi,

I'm using a glibc system header <sys/stat.h> which defines a C struct
'stat'. Furthermore, I'm using the struct 'dirent', defined in <dirent.h>.

Now, at one point in my code I'm holding an std::list of dirents:

std::list< dirent > mylist;

This works.

Now, I wanted to extend the list to hold pairs of dirent/stat:

std::list< std::pair< dirent, stat > > mynewlist;

Now, the compiler (g++ 3.3.4) says he doesn't know a type called 'stat'. So
I tried the C-style notation for instantiating structs:

std::list< std::pair< dirent, struct stat > > mynewlist;

This works. I find it rather odd that I can pass 'dirent' without a
preceding 'struct', but for 'stat' I have to do it the C way to calm the
compiler.


In this case, there is a function called AND a struct called stat.

i.e. func:
stat(const char*, stat*)

and
struct stat.
Jul 22 '05 #2
Matthias Käppler wrote in news:co******** *****@news.t-online.com in
comp.lang.c++:
Hi,

I'm using a glibc system header <sys/stat.h> which defines a C struct
'stat'. Furthermore, I'm using the struct 'dirent', defined in
<dirent.h>.

Now, at one point in my code I'm holding an std::list of dirents:

std::list< dirent > mylist;

This works.

Now, I wanted to extend the list to hold pairs of dirent/stat:

std::list< std::pair< dirent, stat > > mynewlist;

Now, the compiler (g++ 3.3.4) says he doesn't know a type called
'stat'. So I tried the C-style notation for instantiating structs:

std::list< std::pair< dirent, struct stat > > mynewlist;

This works. I find it rather odd that I can pass 'dirent' without a
preceding 'struct', but for 'stat' I have to do it the C way to calm
the compiler.

So, is there a rule of thumb in which cases I need the C-notation?
Frankly I was quite sure that you don't need it at all in C++.


#include <list>
#include <utility>

struct dirent {};
struct stat {};

int stat; /* <- *note* */

typedef std::list< std::pair< dirent, struct stat > > list_t;

Remove the defenition "int stat;" and the "struct" should nolonger
be needed.

Its also possible that struct stat is undefined, in which case
you should also get "struct stat is an incomplete type" errors
or some such.

HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #3
"Matthias Käppler" <no****@digital raid.com> wrote...
I'm using a glibc system header <sys/stat.h> which defines a C struct
'stat'. Furthermore, I'm using the struct 'dirent', defined in <dirent.h>.
How are they defined there? Neither header is standard, so its contenst
and the definitions of those structures are unknown in C++.
Now, at one point in my code I'm holding an std::list of dirents:

std::list< dirent > mylist;

This works.

Now, I wanted to extend the list to hold pairs of dirent/stat:

std::list< std::pair< dirent, stat > > mynewlist;

Now, the compiler (g++ 3.3.4) says he doesn't know a type called 'stat'.
So
I tried the C-style notation for instantiating structs:

std::list< std::pair< dirent, struct stat > > mynewlist;

This works. I find it rather odd that I can pass 'dirent' without a
preceding 'struct', but for 'stat' I have to do it the C way to calm the
compiler.

So, is there a rule of thumb in which cases I need the C-notation? Frankly
I
was quite sure that you don't need it at all in C++.


That depends on how those things are defined. Another possibility is that
there is something else in your program called 'stat' and by adding the
keyword 'struct' you tell the compiler that you actually mean the type and
not something else.

Look in those headers, pull out the definitions for those structs into
a separate file, see what the difference is between them.

V
Jul 22 '05 #4

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

Similar topics

0
2494
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its last year we got traffic of between 2000 - 2500 unique visitors per day. We are now about to re-launch the site from Sweden and we need to purchase a script to run it. Having looked at what is available on the net I have realised that we need a...
6
2191
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
2448
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to parse them to have a tree representation such as :
8
2852
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl list class must Ioverride in order for this to work?
3
2644
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If you need more detail I can be glad to prove all my points. Our goal is to make logical systems. We don't want php,perl, or c++ making all the procedure calls and having the host language to be checking for errors and handleing all the...
2
1956
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a valid IP Address", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Hand) txtIPAddress.Focus() Return End If
5
2961
by: HotRod | last post by:
I am new to this so please go easy. We currently have some students doing some work on some web based tracking documents for us. They are currently using VB .net to develop what we requested. Anyway I've been calling my local ISP's and no one supports .net it seems to be all apache and MySQL. I'm wondering if everyone here can answer a few questions. 1) Can I run vb .net web pages on a regular IIS server without the .net extensions? 2)...
8
2760
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only the sequence nos and it should be such that i can access it through the structure .plz help me .
11
4512
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any AutoNumber* fields in them. Correct me if I'm wrong, but I'm assuming this means that I cannot now alter these existing Access tables and change their primary key to an "AutoNumber" type. If I'm right about this, I need some suggestions as to the...
0
3978
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
0
9978
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
9819
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
10811
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
10919
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
10461
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...
1
8015
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
5846
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...
1
4674
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
3275
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.