Thread: trying to understand headers

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    35

    trying to understand headers

    extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;

    how does one read above?

    I was thinking global int type function name ioctl has these (....).. but what is
    __THROW mean???

    btw, where is best resource to understand headers??

    thanks in advance~

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    __THROW can mean anything. It is not defined by the standard

  3. #3
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    This is a system-specific issue, and does not apply to C.

    For reference, __THROW is meant to declare the function as capable of
    throwing exceptions (a C++ feature). In C, the macro does nothing.
    I'm not really sure what you mean by "understand headers" but if you're trying to understand <stdio.h> then I truly wish you the best of luck.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well given that it's written in UPPERCASE with leading underscores, it's probably defined as a macro by some other header file.

    In particular, it might be defined as nothing at all for C, and the usual 'throw' for C++.
    Then again, it might not be - you would have to find the actual macros in your header files.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    35
    that's what i don't understand.
    I have gone through other included headers and did not see the __THROW defined anywhere.



    Code:
    #ifndef _SYS_IOCTL_H
    #define _SYS_IOCTL_H    1
    
    #include <features.h>
    
    __BEGIN_DECLS
    
    /* Get the list of `ioctl' requests and related constants.  */
    #include <bits/ioctls.h>
    
    /* Define some types used by `ioctl' requests.  */
    #include <bits/ioctl-types.h>
    
    /* On a Unix system, the system <sys/ioctl.h> probably defines some of
       the symbols we define in <sys/ttydefaults.h> (usually with the same
       values).  The code to generate <bits/ioctls.h> has omitted these
       symbols to avoid the conflict, but a Unix program expects <sys/ioctl.h>
       to define them, so we must include <sys/ttydefaults.h> here.  */
    #include <sys/ttydefaults.h>
    
    /* Perform the I/O control operation specified by REQUEST on FD.
       One argument may follow; its presence and type depend on REQUEST.
       Return value depends on REQUEST.  Usually -1 indicates error.  */
    extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
    Last edited by Salem; 03-22-2010 at 12:42 PM. Reason: [code] tags have [ ], not <>

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by convenientstore View Post
    that's what i don't understand.
    I have gone through other included headers and did not see the __THROW defined anywhere.
    If it is not intended for external use you may not find it declared in a header, you may need to examine the entire source (if available). Kind of irritating, but I have seen this before.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    It seems to be defined on several places. One of them is sys/cdefs.h for me. How it is actually defined depends on some conditions. Here's part of the headerfile that is used for GCC:
    Code:
    # if !defined __cplusplus && __GNUC_PREREQ (3, 3)
    #  define __THROW       __attribute__ ((__nothrow__))
    #  define __NTH(fct)    __attribute__ ((__nothrow__)) fct
    # else
    #  if defined __cplusplus && __GNUC_PREREQ (2,8)
    #   define __THROW      throw ()
    #   define __NTH(fct)   fct throw ()
    #  else
    #   define __THROW
    #   define __NTH(fct)   fct
    #  endif
    # endif
    It seems to specify for C++ that the function won't throw anything, if supported. If not supported, it won't mean anything.

Popular pages Recent additions subscribe to a feed