How to find where types are defined

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • * Tong *

    #1

    How to find where types are defined

    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

    --
  • blargg

    #2
    Re: How to find where types are defined

    In article <05Wdneh1RI-fX2HVnZ2dnUVZ_h GdnZ2d@golden.n et>, * Tong *
    <sun_tong_001@u sers.sourceforg e.netwrote:
    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).

    Comment

    • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

      #3
      Re: How to find where types are defined

      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

      Comment

      • Pete Becker

        #4
        Re: How to find where types are defined

        On 2008-10-20 13:59:24 -0400, Erik Wikström <Erik-wikstrom@telia. comsaid:
        >
        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<cha r>::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)

        Comment

        • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

          #5
          Re: How to find where types are defined

          On 2008-10-22 15:59, Stefan Ram wrote:
          * Tong * <sun_tong_001@u sers.sourceforg e.netwrites:
          >>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::boolalph a #include <ios>
          fmtflags ::std::ios::fmt flags¹ #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

          Comment

          • sean_in_raleigh@yahoo.com

            #6
            Re: How to find where types are defined

            On Oct 20, 1:38 pm, * Tong * <sun_tong_...@u sers.sourceforg e.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

            Comment

            Working...