Error Occured during compilation

Discussion in 'C Programming' started by abdur_rab7@yahoo.co.in, Dec 29, 2005.

  1. Guest

    Hi,

    I am compiling code for nanosleep in CYGWIN.
    During compilation i get the following error

    Socket.cc: In method `bool Socket::hangOnConnection(int = 0)':
    Socket.cc:338: aggregate `struct timespec tmsp' has incomplete type and
    cannot b
    e initialized


    The Source realted to it is

    bool Socket :: hangOnConnection (int nNanoSecond)
    {
    struct timespec tmsp;
    /*tmsp.tv_sec = (time_t) 0;
    if (nNanoSecond) tmsp.tv_nsec = nNanoSecond;
    else tmsp.tv_nsec = 110;
    if (nanosleep (&tmsp, NULL) < 0)
    {
    DEBUG_MSG ("Error occured during hangOn");
    return false;
    }*/
    return true;
    }

    "struct timespec" is defined in <sys/types.h>

    Please suggest me how to debug it

    Best Regards,
    Abdur
    , Dec 29, 2005
    #1
    1. Advertising

  2. Madhav Guest

    wrote:

    >
    > bool Socket :: hangOnConnection (int nNanoSecond)
    > {
    > struct timespec tmsp;
    > /*tmsp.tv_sec = (time_t) 0;
    > if (nNanoSecond) tmsp.tv_nsec = nNanoSecond;


    Please ask this question in a more appropriate newsgroup.
    comp.os.linux.development.* might be a good place.

    --
    Madhav.
    Madhav, Dec 29, 2005
    #2
    1. Advertising

  3. Chuck F. Guest

    wrote:
    >

    .... snip ...
    >
    > The Source realted to it is
    >
    > bool Socket :: hangOnConnection (int nNanoSecond)

    ^^^^ ^^
    Syntax errors.
    To use bool you must #include <stdbool.h>, and be using C99.

    > {
    > struct timespec tmsp;


    Undefined struct.

    > /*tmsp.tv_sec = (time_t) 0;
    > if (nNanoSecond) tmsp.tv_nsec = nNanoSecond;
    > else tmsp.tv_nsec = 110;
    > if (nanosleep (&tmsp, NULL) < 0)


    nanosleep undefined. Missing ')'.

    > {
    > DEBUG_MSG ("Error occured during hangOn");

    DEBUG_MSG undefined
    > return false;


    false undefined

    > }*/
    > return true;


    true undefined

    > }
    >
    > "struct timespec" is defined in <sys/types.h>


    No it isn't. There is no such header file defined in ISO standard
    C. What you have here is neither C nor topical. Get thee to a
    newsgroupery dealing with your language and/or system. When you
    find such post compilable code via cut and paste, not retyping.


    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
    Chuck F., Dec 29, 2005
    #3
  4. "" <> writes:
    > I am compiling code for nanosleep in CYGWIN.
    > During compilation i get the following error
    >
    > Socket.cc: In method `bool Socket::hangOnConnection(int = 0)':
    > Socket.cc:338: aggregate `struct timespec tmsp' has incomplete type and
    > cannot b
    > e initialized
    >
    >
    > The Source realted to it is
    >
    > bool Socket :: hangOnConnection (int nNanoSecond)
    > {
    > struct timespec tmsp;
    > /*tmsp.tv_sec = (time_t) 0;
    > if (nNanoSecond) tmsp.tv_nsec = nNanoSecond;
    > else tmsp.tv_nsec = 110;
    > if (nanosleep (&tmsp, NULL) < 0)
    > {
    > DEBUG_MSG ("Error occured during hangOn");
    > return false;
    > }*/
    > return true;
    > }
    >
    > "struct timespec" is defined in <sys/types.h>
    >
    > Please suggest me how to debug it


    Your code is C++, not C. comp.lang.c++ is down the hall on the left.

    Parts of your code could be valid C. I'm suspicious about the "has
    incomplete type and cannot be initialized" message, since you don't
    actually initialize tmpsp. You say that struct timespec is defined in
    <sys/types.h>, but the code you posted doesn't have a #include for
    that header.

    Write a small, self-contained program that illustrates the problem.
    Write it in either C or C++, and post to the appropriate newsgroup.
    Post the exact code that you fed to the compiler; don't try to re-type
    it or summarize it.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Dec 29, 2005
    #4
  5. Hi,

    Normally in Solaris compiler (workshop 6 update 2) the defination of
    struct timespec is present in sys/time_impl.h, But you don't have to
    include this file directly.

    Instead of that please include <time.h> this wiill include time_impl.h
    implicitly.

    If you wish to debug the error, then please run the c preprocessor on
    the compilation and redirect to the file, then you can see the list of
    include files when you are compiling your program.


    HTH
    Rahul
    Rahul Chandok, Dec 29, 2005
    #5
  6. "" <> writes:

    > Hi,
    >
    > I am compiling code for nanosleep in CYGWIN.
    > During compilation i get the following error
    >
    > Socket.cc: In method `bool Socket::hangOnConnection(int = 0)':
    > Socket.cc:338: aggregate `struct timespec tmsp' has incomplete type and
    > cannot b
    > e initialized
    >
    >
    > The Source realted to it is
    >
    > bool Socket :: hangOnConnection (int nNanoSecond)
    > {
    > struct timespec tmsp;
    > /*tmsp.tv_sec = (time_t) 0;
    > if (nNanoSecond) tmsp.tv_nsec = nNanoSecond;
    > else tmsp.tv_nsec = 110;
    > if (nanosleep (&tmsp, NULL) < 0)
    > {
    > DEBUG_MSG ("Error occured during hangOn");
    > return false;
    > }*/
    > return true;
    > }


    Here are the error messages I get:

    cpp.c:1: error: syntax error before "Socket"
    cpp.c:2: warning: return type defaults to `int'
    cpp.c: In function `hangOnConnection':
    cpp.c:3: error: storage size of 'tmsp' isn't known
    cpp.c:12: error: `true' undeclared (first use in this function)
    cpp.c:12: error: (Each undeclared identifier is reported only once
    cpp.c:12: error: for each function it appears in.)
    cpp.c:3: warning: unused variable `tmsp'
    cpp.c: At top level:
    cpp.c:1: warning: unused parameter 'nNanoSecond'

    I suggest that you either fix the syntax errors and repost, or
    post to a group where the code above is syntactically correct.
    (comp.lang.c++ comes to mind).

    > "struct timespec" is defined in <sys/types.h>


    Neither C or C++ has such a header.

    /Niklas Norrthon
    Niklas Norrthon, Dec 29, 2005
    #6
  7. Guest

    Hi Keith Thompson,

    Here is the sample programm in C

    #include <stdio.h>
    #include <sys/types.h>
    #include <time.h>

    int hangOn (int nNanoSecond)
    {
    struct timespec tmsp;
    /*tmsp.tv_sec = (time_t) 0;
    if (nNanoSecond) tmsp.tv_nsec = nNanoSecond;
    else tmsp.tv_nsec = 110;
    if (nanosleep (&tmsp, NULL) < 0) return -1;
    */
    return (0);

    }


    int main ()
    {
    printf ("\n The function hangOn is being called\n");
    printf ("\n The Return Value is : %d\n", hangOn (110));
    return (0);
    }

    I get two different errors when i compile it with 'gcc' as well as
    'g++' compiler

    gcc compilation
    -----------------------
    bash-2.02$ gcc -o tes test.c
    test.c: In function `hangOn':


    g++ compilation
    -----------------------test.c:7: storage size of `tmsp' isn't known
    bash-2.02$ g++ -o tes test.c
    test.c: In function `int hangOn(int)':
    test.c:7: aggregate `struct timespec tmsp' has incomplete type and
    cannot be ini
    tialized
    bash-2.02$

    the structure defined in <sys/types.h>

    The definition part alone
    ---------------------------------------
    #ifndef __time_t_defined
    typedef _TIME_T_ time_t;
    #define __time_t_defined

    /* Time Value Specification Structures, P1003.1b-1993, p. 261 */

    struct timespec {
    time_t tv_sec; /* Seconds */
    long tv_nsec; /* Nanoseconds */
    };

    struct itimerspec {
    struct timespec it_interval; /* Timer period */
    struct timespec it_value; /* Timer expiration */
    };
    #endif

    If there is some patch for cygwin, please let me know about it

    Best Regards,
    Abdur
    , Dec 29, 2005
    #7
  8. Richard Bos Guest

    "" <> wrote:

    > Hi Keith Thompson,


    This is a newsgroup, not a personal conversation.

    > Here is the sample programm in C


    _The_ sample program? A sample program of what, exactly? Learn to quote
    context, man! Google Beta's brokenness is no excuse for you to be just
    as broken.

    > #include <stdio.h>
    > #include <sys/types.h>


    This is not C...

    > #include <time.h>
    >
    > int hangOn (int nNanoSecond)
    > {
    > struct timespec tmsp;


    ....nor is this...

    > /*tmsp.tv_sec = (time_t) 0;
    > if (nNanoSecond) tmsp.tv_nsec = nNanoSecond;
    > else tmsp.tv_nsec = 110;


    ....or either of these...

    > if (nanosleep (&tmsp, NULL) < 0) return -1;


    ....or this.

    > */
    > return (0);
    >
    > }
    >
    >
    > int main ()
    > {
    > printf ("\n The function hangOn is being called\n");
    > printf ("\n The Return Value is : %d\n", hangOn (110));
    > return (0);
    > }
    >
    > I get two different errors when i compile it with 'gcc' as well as
    > 'g++' compiler
    >
    > gcc compilation
    > -----------------------
    > bash-2.02$ gcc -o tes test.c
    > test.c: In function `hangOn':


    That's not the whole error message. Besides, with that command line,
    you're not compiling C, but Ganuck. Your problem seems to be with the
    Gnu extensions; you'll need to ask about those in a gcc newsgroup.
    They're off-topic here.

    > the structure defined in <sys/types.h>


    _Now_ he tells us.

    > The definition part alone
    > ---------------------------------------
    > #ifndef __time_t_defined
    > typedef _TIME_T_ time_t;
    > #define __time_t_defined
    >
    > /* Time Value Specification Structures, P1003.1b-1993, p. 261 */
    >
    > struct timespec {
    > time_t tv_sec; /* Seconds */
    > long tv_nsec; /* Nanoseconds */
    > };
    >
    > struct itimerspec {
    > struct timespec it_interval; /* Timer period */
    > struct timespec it_value; /* Timer expiration */
    > };
    > #endif


    Note that all of this
    - only defines the structs, and doesn't declare the nanosleep()
    function, let alone explain its use;
    - does not agree with the error message you posted, for the code you
    posted. Not unless <stdio.h> #defines __time_t_defined but not those
    structs, which would be legal but very surprising.

    > If there is some patch for cygwin,


    ....it is on-topic in a cygwin newsgroup. Or possibly a gcc newsgroup;
    please have the decency to check what is on-topic there before posting,
    unlike your behaviour here.

    Richard
    Richard Bos, Dec 29, 2005
    #8
  9. Guest

    Thanks Richard

    > _The_ sample program? A sample program of what, exactly? Learn to quote

    context, man! Google Beta's brokenness is no excuse for you to be just
    as broken.

    May be you are good in giving context......

    > the structure defined in <sys/types.h>


    >_Now_ he tells us.



    May be u did not see the earlier loop

    > "struct timespec" is defined in <sys/types.h>

    "No it isn't. There is no such header file defined in ISO standard
    C. What you have here is neither C nor topical. Get thee to a
    newsgroupery dealing with your language and/or system. When you
    find such post compilable code via cut and paste, not retyping."

    You can help me out rather than pointing out mistakes.

    Abdur
    , Dec 29, 2005
    #9
  10. Guest

    Posting it again as per request

    #include <stdio.h>
    #include <sys/types.h>
    #include <time.h>
    int hangOn (int nNanoSecond)
    {
    struct timespec tmsp;
    /*tmsp.tv_sec = (time_t) 0;
    if (nNanoSecond) tmsp.tv_nsec = nNanoSecond;
    else tmsp.tv_nsec = 110;
    if (nanosleep (&tmsp, NULL) < 0) return -1;
    */
    return (0);


    }

    int main ()
    {
    printf ("\n The function hangOn is being called\n");
    printf ("\n The Return Value is : %d\n", hangOn (110));
    return (0);


    }
    , Dec 29, 2005
    #10
  11. Chuck F. Guest

    Rahul Chandok wrote:
    >
    > Normally in Solaris compiler (workshop 6 update 2) the
    > defination of struct timespec is present in sys/time_impl.h, But
    > you don't have to include this file directly.
    >
    > Instead of that please include <time.h> this wiill include
    > time_impl.h implicitly.


    Wrong again. time.h connects to the facility, but you have no idea
    how. Your system is not canonical.
    >
    > If you wish to debug the error, then please run the c
    > preprocessor on the compilation and redirect to the file, then
    > you can see the list of include files when you are compiling
    > your program.


    From this viewpoint it appears that Indian users of google are
    especially dense or uncooperative. They seem to persist in failing
    to quote properly, even after being given repeated instructions in
    how to do so. They also have a nasty tendency to use childish
    abbreviations (not the above user). Is this some sort of cultural
    failing or what?

    It is possible that I am mistaken, since the Indian names are
    fairly obvious to classify, and the names of other misusers of
    usenet tend to be more varied.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
    Chuck F., Dec 29, 2005
    #11
  12. Chuck F. Guest

    wrote:
    >

    .... snip ...
    >
    > You can help me out rather than pointing out mistakes.


    If you correct the silly, careless, and rude mistakes you might be
    able to communicate over Usenet.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
    Chuck F., Dec 29, 2005
    #12
  13. said:

    > You can help me out rather than pointing out mistakes.


    By pointing out your mistakes, he is helping you out.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
    Richard Heathfield, Dec 29, 2005
    #13
  14. Richard Bos Guest

    "" <> wrote:

    > Thanks Richard
    >
    > > _The_ sample program? A sample program of what, exactly? Learn to quote

    > context, man! Google Beta's brokenness is no excuse for you to be just
    > as broken.
    >
    > May be you are good in giving context......


    That sentence makes no sense. Search this group for references to Google
    - context - quoting. I believe Chuck F. has a useful link in his .sig.

    > > the structure defined in <sys/types.h>

    >
    > >_Now_ he tells us.

    >
    > May be u did not see the earlier loop


    Again, non sequitur. There was no loop in your post. There is no loop in
    this entire thread. What are you talking about, man?

    > > "struct timespec" is defined in <sys/types.h>

    > "No it isn't. There is no such header file defined in ISO standard
    > C. What you have here is neither C nor topical. Get thee to a
    > newsgroupery dealing with your language and/or system. When you
    > find such post compilable code via cut and paste, not retyping."


    I did not write this. Chuck F. did. Do not quote it (however brokenly)
    as if I did.

    > You can help me out rather than pointing out mistakes.


    You can let yourself be helped rather than resisting decent netizenship.
    Your question is off-topic here; what you wrote is POSIX-extended (or
    possibly Gnu) C, not ISO C, and it appears (though you hardly have given
    sufficient material to nail it down solidly) that the problem is in the
    POSIX bits.

    Richard
    Richard Bos, Dec 29, 2005
    #14
  15. "" <> writes:
    > Hi Keith Thompson,


    Why are you addressing me personally? This is a newgroup, not e-mail.

    I will ask you again to read <http://cfaj.freeshell.org/google/>.
    Please please please don't post to Usenet again until you read this
    web page and follow its advice.

    > Here is the sample programm in C
    >
    > #include <stdio.h>
    > #include <sys/types.h>
    > #include <time.h>


    Again, <sys/types.h> is not a standard C header. (It's probably
    defined by POSIX, but not by ISO C.) It is therefore off-topic in
    this newsgroup.

    > int hangOn (int nNanoSecond)
    > {
    > struct timespec tmsp;
    > /*tmsp.tv_sec = (time_t) 0;
    > if (nNanoSecond) tmsp.tv_nsec = nNanoSecond;
    > else tmsp.tv_nsec = 110;
    > if (nanosleep (&tmsp, NULL) < 0) return -1;
    > */
    > return (0);
    >
    > }


    Several lines of this function are commented out. I suggest deleting
    them before you post your code; they're only causing confusion.

    > int main ()
    > {
    > printf ("\n The function hangOn is being called\n");
    > printf ("\n The Return Value is : %d\n", hangOn (110));
    > return (0);
    > }
    >
    > I get two different errors when i compile it with 'gcc' as well as
    > 'g++' compiler
    >
    > gcc compilation
    > -----------------------
    > bash-2.02$ gcc -o tes test.c
    > test.c: In function `hangOn':


    If you don't show us the actual error message, we can't help you.

    > g++ compilation

    [snip]

    g++ is a C++ compiler. We don't care what it does. If you have
    questions about C++, post to comp.lang.c++.

    <OFF-TOPIC>
    I compiled your code under Cygwin, and got no error messages. I don't
    know what your problem is. Perhaps you need to upgrade your system.
    (Cygwin makes this easy to do, using the same mechanism you used to
    install it in the first place.)
    </OFF-TOPIC>

    If you can reproduce the problem with a *portable* C program that
    doesn't depend on any non-standard headers, we may be able to help
    you. Try incorporating the relevant declarations from <sys/types.h>
    into your program, and dropping the "#include <sys/types.h>". Or post
    to a Cygwin mailing list; see the Cygwin web site for details.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Dec 29, 2005
    #15
  16. santosh Guest

    Chuck F. wrote:
    > From this viewpoint it appears that Indian users of google are
    > especially dense or uncooperative. They seem to persist in failing
    > to quote properly, even after being given repeated instructions in
    > how to do so. They also have a nasty tendency to use childish
    > abbreviations (not the above user). Is this some sort of cultural
    > failing or what?


    <OT>
    More like *lack* of culture with regard to computers. Computers and
    USENET existed *much* before they were even remotely known in India,
    (indeed this applies to other developing countries too).

    Since most of these guys tend to spend a lot of time using Chat and
    Instant Messaging, they just don't get the concept behind attribution.
    In addition when they see the 'Tree' view offered in Google Groups they
    don't see why they should take the pain to include blocks of text.

    There is no love of science or technology for it's sake. For the vast
    majority here it's a means of minting bucks rendering "boot polishing"
    to the west.

    > It is possible that I am mistaken, since the Indian names are
    > fairly obvious to classify, and the names of other misusers of
    > usenet tend to be more varied.


    I hang around in alt.lang.asm and I have noticed many Italians, East
    Europeans and others also failing to uphold correct USENET etiquette.
    It seems to be rather common among most people who are not from
    W.Europe, USA, Australia or Russia. Those cultures which have not
    actively developed these technologies but instead simply adopt them
    don't seem to display the highest standards of Netiquette.

    > "If you want to post a followup via groups.google.com, don't use
    > the broken "Reply" link at the bottom of the article. Click on
    > "show options" at the top of the article, then click on the
    > "Reply" at the bottom of the article headers." - Keith Thompson
    > More details at: <http://cfaj.freeshell.org/google/>


    This won't work with people who only know the language of time and
    money. It's hopeless to introduce "globalisation" and remain such a
    prude as well. Six billion elephants can all be expected to be white.

    </OT>
    santosh, Dec 29, 2005
    #16
  17. Guest

    Thank you all, there was a problem with my cygwin installation.
    Installed the patch and able to compile it without any problem.

    Thank you for your valuable comments; it helped me a lot for nailing
    down to the exact problem.

    Chuck F. wrote:
    >From this viewpoint it appears that Indian users of google are
    >especially dense or uncooperative. They seem to persist in failing
    >to quote properly, even after being given repeated instructions in
    >how to do so. They also have a nasty tendency to use childish
    >abbreviations (not the above user). Is this some sort of cultural
    >failing or what?


    May be it was my fault. Please do not blame the total Indian population
    for that

    Wish u all a Happy and Prosperous New Year

    Best Regards,
    Abdur
    , Dec 30, 2005
    #17
  18. In article <>,
    <> wrote:
    ....
    >Wish u all a Happy and Prosperous New Year


    shrlyumeen

    wsh u al a hpy&prsprsnwyr
    Kenny McCormack, Dec 30, 2005
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. madhukar

    error occured

    madhukar, Dec 29, 2003, in forum: VHDL
    Replies:
    0
    Views:
    643
    madhukar
    Dec 29, 2003
  2. Sven Schimmel
    Replies:
    1
    Views:
    487
  3. Sam-I-Am
    Replies:
    3
    Views:
    1,526
    Sam-I-Am
    Jun 10, 2004
  4. Feng Xuebin
    Replies:
    0
    Views:
    350
    Feng Xuebin
    Jun 30, 2004
  5. Replies:
    3
    Views:
    167
    Curt Hibbs
    Feb 6, 2006
Loading...

Share This Page