Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Error Occured during compilation (http://www.velocityreviews.com/forums/t440686-error-occured-during-compilation.html)

abdur_rab7@yahoo.co.in 12-29-2005 05:44 AM

Error Occured during compilation
 
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


Madhav 12-29-2005 06:09 AM

Re: Error Occured during compilation
 
abdur_rab7@yahoo.co.in 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.


Chuck F. 12-29-2005 06:54 AM

Re: Error Occured during compilation
 
abdur_rab7@yahoo.co.in 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/>

Keith Thompson 12-29-2005 07:10 AM

Re: Error Occured during compilation
 
"abdur_rab7@yahoo.co.in" <abdur_rab7@yahoo.co.in> 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) kst-u@mib.org <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.

Rahul Chandok 12-29-2005 07:21 AM

Re: Error Occured during compilation
 
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


Niklas Norrthon 12-29-2005 08:29 AM

Re: Error Occured during compilation
 
"abdur_rab7@yahoo.co.in" <abdur_rab7@yahoo.co.in> 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

abdur_rab7@yahoo.co.in 12-29-2005 08:30 AM

Re: Error Occured during compilation
 
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


Richard Bos 12-29-2005 08:43 AM

Re: Error Occured during compilation
 
"abdur_rab7@yahoo.co.in" <abdur_rab7@yahoo.co.in> 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

abdur_rab7@yahoo.co.in 12-29-2005 09:34 AM

Re: Error Occured during compilation
 
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


abdur_rab7@yahoo.co.in 12-29-2005 10:41 AM

Re: Error Occured during compilation
 
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);


}



All times are GMT. The time now is 08:10 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.