CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    Join Date
    Jun 2011
    Posts
    19

    Re: Getting problem with using struct timeval

    Hi,
    Probably you are right and you are right in the sense these code are cross platform code.
    I have been using visual studio 2010 professional. So far I know , i think the SDK installed is right one. I just removed those macro directives and included the header files like :


    #include <WinSock2.h>
    #include <Windows.h>
    #include <stdio.h>

    Now, what I am getting error is :

    1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winnt.h(4277): error C2040: 'CONTEXT' : '_CONTEXT' differs in levels of indirection from 'binding *'
    1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winuser.h(5341): error C2365: 'INPUT' : redefinition; previous definition was 'enumerator'
    1>c:\documents and settings\xyz\desktop\abc\test.h(72) : see declaration of 'INPUT'
    1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(16): error C2011: 'timeval' : 'struct' type redefinition
    1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\WinSock2.h(176) : see declaration of 'timeval'


    Could you please know what Shall i do to overcome those error?

  2. #17
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Getting problem with using struct timeval

    Quote Originally Posted by __bairagi View Post
    ... So far I know , i think the SDK installed is right one. I just removed those macro directives and included the header files like :
    Code:
                         #include <WinSock2.h>  
                         #include <Windows.h>
                         #include <stdio.h>
    Now, what I am getting error is :
    Code:
    ...
                         1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(16): error C2011: 'timeval' : 'struct' type redefinition
                         1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\WinSock2.h(176) : see declaration of 'timeval'
    Why are you using two definitions of timeval: one in the <WinSock2.h> and another in C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h ?
    Victor Nijegorodov

  3. #18
    Join Date
    Jun 2011
    Posts
    19

    Re: Getting problem with using struct timeval

    I am not so sure about it. I have not included <sys/time.h> in the header file and I have no idea why it is showing the inclusion of <sys/time.h>. Could you please let me know what exactly I have to do get rid of this?

  4. #19
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Getting problem with using struct timeval

    First try to comment out (if you, of course, don't use sockets!) the
    Code:
      #include <WinSock2.h>
    Victor Nijegorodov

  5. #20
    Join Date
    Jun 2011
    Posts
    19

    Re: Getting problem with using struct timeval

    Hi,

    once I remove winsock2.h I get the following errors:



    >C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(20): error C2061: syntax error : identifier 'suseconds_t'
    1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(21): error C2059: syntax error : '}'
    1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(39): error C2079: 'it_interval' uses undefined struct 'timeval'
    1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(40): error C2079: 'it_value' uses undefined struct 'timeval'

  6. #21
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Getting problem with using struct timeval

    Quote Originally Posted by __bairagi View Post
    once I remove winsock2.h I get the following errors:
    Code:
    >C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(20): error C2061: syntax error : identifier 'suseconds_t'
    1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(21): error C2059: syntax error : '}'
    1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(39): error C2079: 'it_interval' uses undefined struct 'timeval'
    1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h(40): error C2079: 'it_value' uses undefined struct 'timeval
    '
    Where does this file C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/time.h come from?
    The "standard" VC2010 installation does not contain such a file! (and VladimirF already mentioned it).
    There is C:\Program Files\Microsoft Visual Studio 10.0\VC\include\time.h
    and there is C:\Program Files\Microsoft Visual Studio 10.0\VC\include\sys/timeb.h...

    Could you show *your* version of time.h file?
    Victor Nijegorodov

  7. #22
    Join Date
    Jun 2011
    Posts
    19

    Re: Getting problem with using struct timeval

    Hi,
    Thanks for your reply.I think my VS contains some header files of cygwin. Following is the version it is showing. Do you think it is error in installation of visual studio? or I did some mistakes during creating the project.


    /* time.h -- An implementation of the standard Unix <sys/time.h> file.
    Written by Geoffrey Noer <noer@cygnus.com>
    Public domain; no rights reserved. */


    Actually I did following to create project.

    File->project from external source-> vc++ -> use visual studio for console->ok

  8. #23
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Getting problem with using struct timeval

    Quote Originally Posted by __bairagi View Post
    Hi,
    Thanks for your reply.I think my VS contains some header files of cygwin. Following is the version it is showing. Do you think it is error in installation of visual studio? or I did some mistakes during creating the project.
    I think (and am pretty sure) that you did some mistakes during creating the project.

    Quote Originally Posted by __bairagi View Post
    /* time.h -- An implementation of the standard Unix <sys/time.h> file.
    Written by Geoffrey Noer <noer@cygnus.com>
    Public domain; no rights reserved. */
    Well, what does this Unix file have to do with the Windows CRT?

    Quote Originally Posted by __bairagi View Post
    Actually I did following to create project.

    File->project from external source-> vc++ -> use visual studio for console->ok
    I don't see any problem here.
    Last edited by VictorN; June 28th, 2011 at 04:22 AM.
    Victor Nijegorodov

  9. #24
    Join Date
    Jun 2011
    Posts
    19

    Re: Getting problem with using struct timeval

    Hello VictorN,

    Thanks a lot for your help.It really worked for my after removing the the header file <sys/time.h>. But still I am bugging with the error which is the last one amongst many errors. Following is the error and of course I am expecting another help from you.


    1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winnt.h(4277): error C2040: 'CONTEXT' : '_CONTEXT' differs in levels of indirection from 'binding *'
    1>C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\winuser.h(5341): error C2365: 'INPUT' : redefinition; previous definition was 'enumerator'

  10. #25
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Getting problem with using struct timeval

    Victor Nijegorodov

  11. #26
    Join Date
    Jun 2011
    Posts
    19

    Re: Getting problem with using struct timeval

    I found the solution for these kind of error messages.

    1. For the error C2040 in my case, CONTEXT in my source code was defined as structure . Same Keyword in the
    header file winnt.h it is defined as struct pointer. So this conflict was creating error.

    2.Similar was the case for for error c2365.

    Thanks everybody for your help.

  12. #27
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Getting problem with using struct timeval

    Quote Originally Posted by __bairagi View Post
    I found the solution for these kind of error messages.

    1. For the error C2040 in my case, CONTEXT in my source code was defined as structure . Same Keyword in the
    header file winnt.h it is defined as struct pointer. So this conflict was creating error.

    2.Similar was the case for for error c2365.

    Thanks everybody for your help.
    It isn't wise to create constants and names that could be easily duplicated by another header. Words such as CONTEXT, FILE, TEXT, SECURITY, etc. should not be used for your own definitions.

    Instead YOURAPP_CONTEXT or something that is almost impossible for it to be duplicated, and at the same time, makes sense.

    Regards,

    Paul McKenzie

  13. #28
    Join Date
    Jun 2011
    Posts
    19

    Re: Getting problem with using struct timeval

    To overcome those error, I just renamed those Keywords into another name appending some number like CONTEXT1, which gives meaning to my source code and does not conflict with header files as well.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured