[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

How to find where types are defined

* Tong *

10/20/2008 5:38:00 PM

Hi,

Simple questions, How to find where types are defined?
And, how can I find which paths are considered standard by my g++?

I get,

error: 'off_t' does not name a type

I know that if I add the following bunch

#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

it will go away. but how can I find which exactly .h file defines the
type off_t?

Ref:

$ apropos off_t

$ man -k off_t

PS. I know the .h is not the "correct" include syntax for cpp files, but
this is a legacy cpp program that I want to alter as little as possible.

thanks

--
6 Answers

blargg.h4g

10/20/2008 5:58:00 PM

0

In article <05Wdneh1RI-fX2HVnZ2dnUVZ_hGdnZ2d@golden.net>, * Tong *
<sun_tong_001@users.sourceforge.net> wrote:
> Simple questions, How to find where types are defined?
> And, how can I find which paths are considered standard by my g++?
>
> I get,
>
> error: 'off_t' does not name a type
>
> I know that if I add the following bunch
>
> #include <sys/stat.h>
> #include <sys/mman.h>
> #include <sys/ioctl.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> it will go away. but how can I find which exactly .h file defines the
> type off_t?

Divide-and-conquer. Remove half the #include lines, then recompile. If the
error occurs, it's defined in the half you removed, otherwise it's defined
in the half you kept. Repeat this procedure with the half it's in, until
you get down to a single header file. Look up "binary search" for more.

For information about your compiler, refer to documentation or the
appropriate newsgroup (there's probably one for g++, part of the GNU
Compiler Collection).

Erik Wikström

10/20/2008 5:59:00 PM

0

On 2008-10-20 19:38, * Tong * wrote:
> Hi,
>
> Simple questions, How to find where types are defined?
> And, how can I find which paths are considered standard by my g++?

By reading the gcc manual.

> I get,
>
> error: 'off_t' does not name a type
>
> I know that if I add the following bunch
>
> #include <sys/stat.h>
> #include <sys/mman.h>
> #include <sys/ioctl.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> it will go away. but how can I find which exactly .h file defines the
> type off_t?

C++ does not define any off_t, but there is a OFF_T which can be found
in <ios>. POSIX on the other hand does define a off_t in <sys/types.h>.

--
Erik Wikström

Pete Becker

10/20/2008 6:41:00 PM

0

On 2008-10-20 13:59:24 -0400, Erik Wikström <Erik-wikstrom@telia.com> said:

>
> C++ does not define any off_t, but there is a OFF_T which can be found
> in <ios>. POSIX on the other hand does define a off_t in <sys/types.h>.

Actually, there isn't an OFF_T in C++. That name is used in the
standard as a placeholder for an implementation-specific type that
meets certain requirements, so it can be used to define the nested type
std::traits<char>::off_type, etc.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

ram

10/22/2008 1:59:00 PM

0

* Tong * <sun_tong_001@users.sourceforge.net> writes:
>it will go away. but how can I find which exactly .h file defines the
>type off_t?

The question still is open:

In C++, we have certain »parts« of the language (including the
standard library) that require certain include directives.

These parts include:

- names
- operators
- preprocessor names

. (Did I miss some part type?)

Now, given any part, say, »fmtflags«¹, one would like to know
which include directive is required.

This can not be tried by using a C++ implementation, because
some include directives might declare the part by coincidence,
but not because ISO/IEC 14882:2003(E) requires them to do so.

One would like to have a means to look-up each part, a list
of all those parts (possibly with their fully qualified name),
where each entry gives a specific include directive that is
guaranteed by ISO/IEC 14882:2003(E) to declare this part.

boolalpha ::std::boolalpha #include <ios>
fmtflags ::std::ios::fmtflags¹ #include <ios>
ostream ::std::ostream #include <ostream>
setprecision #include <iomanip>
<< #include <iostream>
.... ... ...

So, the question is, where to find such a list, or whether
there is a simple procedure to get the last column from the
first one.

1) I am not sure about »fmtflags«, several sources include
different »fmtflags«, such as »::std::fmtflags«,
»::std::ios::fmtflags«, and »::std::ios_base::fmtflags«.
I do not know, whether all these names are being declared
by the standard library, and when to use which one, but
such a list should list them all, if there are several
»fmtflags«.

Erik Wikström

10/22/2008 3:42:00 PM

0

On 2008-10-22 15:59, Stefan Ram wrote:
> * Tong * <sun_tong_001@users.sourceforge.net> writes:
>>it will go away. but how can I find which exactly .h file defines the
>>type off_t?
>
> The question still is open:
>
> In C++, we have certain »parts« of the language (including the
> standard library) that require certain include directives.
>
> These parts include:
>
> - names
> - operators
> - preprocessor names
>
> . (Did I miss some part type?)
>
> Now, given any part, say, »fmtflags«¹, one would like to know
> which include directive is required.
>
> This can not be tried by using a C++ implementation, because
> some include directives might declare the part by coincidence,
> but not because ISO/IEC 14882:2003(E) requires them to do so.
>
> One would like to have a means to look-up each part, a list
> of all those parts (possibly with their fully qualified name),
> where each entry gives a specific include directive that is
> guaranteed by ISO/IEC 14882:2003(E) to declare this part.
>
> boolalpha ::std::boolalpha #include <ios>
> fmtflags ::std::ios::fmtflags¹ #include <ios>
> ostream ::std::ostream #include <ostream>
> setprecision #include <iomanip>
> << #include <iostream>
> ... ... ...
>
> So, the question is, where to find such a list, or whether
> there is a simple procedure to get the last column from the
> first one.

To my knowledge there is no such list today, but if you have a copy of
the standard you can search it for the identifier or whatever and find
out what header declares it.

--
Erik Wikström

sean_in_raleigh

10/22/2008 4:01:00 PM

0

On Oct 20, 1:38 pm, * Tong * <sun_tong_...@users.sourceforge.net>
wrote:
> Hi,
>
> Simple questions, How to find where types are defined?
Get the compiler to print the preprocessed input, and
search for your type:

g++ -E foo.cpp | egrep '^#|\<off_t\>'| grep -B10 off_t

> And, how can I find which paths are considered standard by my g++?

g++ -v foo.cpp

Sean