c identifier error

This is a discussion on c identifier error within the C Programming forums, part of the General Programming Boards category; Good day everyone, i have this program which is for Bioinformatics data processing, below is the error and what follows ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    10

    Post c identifier error

    Good day everyone, i have this program which is for Bioinformatics data processing, below is the error and what follows is the program..
    ------ Build started: Project: Biodata_main, Configuration: Debug Win32 ------
    Compiling...
    Biodata_main.c
    d:\documents and settings\olawale\my documents\visual studio 2008\projects\biodata\biodata_main.c(13) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    d:\documents and settings\olawale\my documents\visual studio 2008\projects\biodata\biodata_main.c(133) : error C2065: '__argc' : undeclared identifier
    d:\documents and settings\olawale\my documents\visual studio 2008\projects\biodata\biodata_main.c(133) : error C2065: '__argv' : undeclared identifier
    d:\documents and settings\olawale\my documents\visual studio 2008\projects\biodata\biodata_main.c(133) : warning C4047: 'function' : 'const char **' differs in levels of indirection from 'int'
    d:\documents and settings\olawale\my documents\visual studio 2008\projects\biodata\biodata_main.c(133) : warning C4024: 'mclRunMain' : different types for formal and actual parameter 3
    Build log was saved at "file://d:\Documents and Settings\olawale\My Documents\Visual Studio 2008\Projects\Biodata\Debug\BuildLog.htm"
    Biodata_main - 2 error(s), 3 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    BELOW IS THE LINES OF CODE>>THE ERROR POINTS TO THE LAST LINE ON THE PROGRAM
    Code:
     /*
     * Date: Mon Feb 25 00:12:07 2008
     * Arguments: "-B" "macro_default" "-o" "Biodata" "-W" "WinMain:Biodata" "-d"
     * "D:\Documents and Settings\olawale\Desktop\Biodata-24feb\Biodata\src" "-T"
     * "link:exe" "-v" "D:\Documents and
     * Settings\olawale\Desktop\Biodata-24feb\fy1t50h.m" 
     */
    
    #include <stdio.h>
    #include "mclmcr.h"
    #include <windows.h>
    #include <stdlib.h>?
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    extern mclComponentData __MCC_Biodata_component_data;
    
    #ifdef __cplusplus
    }
    #endif
    
    static HMCRINSTANCE _mcr_inst = NULL;
    
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    static int mclDefaultPrintHandler(const char *s)
    {
      return mclWrite(1 /* stdout */, s, sizeof(char)*strlen(s));
    }
    
    #ifdef __cplusplus
    } /* End extern "C" block */
    #endif
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    static int mclDefaultErrorHandler(const char *s)
    {
      int written = 0;
      size_t len = 0;
      len = strlen(s);
      written = mclWrite(2 /* stderr */, s, sizeof(char)*len);
      if (len > 0 && s[ len-1 ] != '\n')
        written += mclWrite(2 /* stderr */, "\n", sizeof(char));
      return written;
    }
    
    #ifdef __cplusplus
    } /* End extern "C" block */
    #endif
    
    /* This symbol is defined in shared libraries. Define it here
     * (to nothing) in case this isn't a shared library. 
     */
    #ifndef LIB_Biodata_C_API 
    #define LIB_Biodata_C_API /* No special import/export declaration */
    #endif
    
    LIB_Biodata_C_API 
    bool MW_CALL_CONV BiodataInitializeWithHandlers(
        mclOutputHandlerFcn error_handler,
        mclOutputHandlerFcn print_handler
    )
    {
      if (_mcr_inst != NULL)
        return true;
      if (!mclmcrInitialize())
        return false;
      if (!mclInitializeComponentInstance(&_mcr_inst, &__MCC_Biodata_component_data,
                                          true, NoObjectType, ExeTarget,
                                          error_handler, print_handler))
        return false;
      return true;
    }
    
    LIB_Biodata_C_API 
    bool MW_CALL_CONV BiodataInitialize(void)
    {
      return BiodataInitializeWithHandlers(mclDefaultErrorHandler,
                                           mclDefaultPrintHandler);
    }
    
    LIB_Biodata_C_API 
    void MW_CALL_CONV BiodataTerminate(void)
    {
      if (_mcr_inst != NULL)
        mclTerminateInstance(&_mcr_inst);
    }
    
    int run_main(int argc, const char **argv)
    {
      int _retval;
      /* Generate and populate the path_to_component. */
      char path_to_component[(PATH_MAX*2)+1];
      separatePathName(argv[0], path_to_component, (PATH_MAX*2)+1);
      __MCC_Biodata_component_data.path_to_component = path_to_component; 
      if (!BiodataInitialize()) {
        return -1;
      }
      _retval = mclMain(_mcr_inst, argc, argv, "fy1t50h", 0);
      if (_retval == 0 /* no error */) mclWaitForFiguresToDie(NULL);
      BiodataTerminate();
    #if defined( _MSC_VER)
      PostQuitMessage(0);
    #endif
      mclTerminateApplication();
      return _retval;
    }
    
    #if defined( _MSC_VER)
    
    #define argc __argc
    #define argv __argv
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
    #else
    int main(int argc, const char **argv)
    
    #endif
    {
      if (!mclInitializeApplication(
        __MCC_Biodata_component_data.runtime_options,
        __MCC_Biodata_component_data.runtime_option_count))
        return 0;
    //int main(int argc, char* argv[])
      return mclRunMain(run_main, argc, argv);
    }

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    #include <stdlib.h>?
    remove ?

    Code:
    #define argc __argc
    #define argv __argv
      return mclRunMain(run_main, argc, argv);
    converts to
    return mclRunMain(run_main, __argc, __argv);

    but vars __argc, __argv are not defined
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
    #define argc __argc
    #define argv __argv
      return mclRunMain(run_main, argc, argv);
    converts to
    Code:
    return mclRunMain(run_main, __argc, __argv);
    but vars __argc, __argv are not defined
    I think MSVC declares __argc and __argv when using WinMain(), which is presumably what this code is trying to take advantage of. However, perhaps this only happens in console mode or something? It would seem this way. http://www.knakkergaard.dk/troels/code.htm
    __argc, __argv

    Code:
    #ifdef _MSDOS
    extern int    __argc;
    extern TCHAR** __argv;
    #endif __argc and __argv isn't prototyped anywhere in antiquated Microsoft compilers. They're practical to have in scope, also outside of main().
    So -- try compiling the code as a console program, not as a Windows one.

    Code:
    int main(int argc, const char **argv)
    Do not make argv const. For reasons I don't feel like explaining, const pointers-to-pointers are asking for trouble. Besides, main() is prototyped as
    Code:
    int main(int, char **);
    No const there.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by dwks View Post
    Code:
    int main(int argc, const char **argv)
    Do not make argv const. For reasons I don't feel like explaining, const pointers-to-pointers are asking for trouble. Besides, main() is prototyped as
    Code:
    int main(int, char **);
    No const there.
    I'm curious whenever you may find the time.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by Dave_Sinkula View Post
    I'm curious whenever you may find the time.
    Uogh! It took me some time to get what you are asking for
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Looks like it came up before but no one knew anything about it: Basic things I need to know (post 42 onwards)

    Unfortunately, I can't remember why myself. I wish I could dig up the book that mentioned why it's not allowed, but I can't find it at the moment.

    I'll keep looking, but I don't think I'll find anything.

    It's possible that I misread or misremembered the passage. It's only the one book I've ever seen it mentioned in.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Aha! I found it! http://c-faq.com/ansi/constmismatch.html
    (Via this thread: http://www.velocityreviews.com/forum...nter-type.html)

    The book I was talking about was C++ Primer Plus, probably 4th edition. There's an online version of it, but unfortunately I think the page I was looking for was page 269, which isn't part of the preview. Still, there is some circumstantial evidence on page 271. http://books.google.ca/books?id=zuyA...NgTs#PPA271,M1
    Using const in that declaration means that show_array() cannot alter the values in any array passed to it. This technique works as long as there is just one level of indirection. Here, for example, the array elements are a fundamental type. But if they were pointers or pointers-to-pointers, you wouldn't use const.
    (Note: I transcribed that paragraph out, because my browser won't let me copy-and-paste it. There might be an error or two in it.)

    But the FAQ is best of all. Enjoy. I'm still trying to understand it myself . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    you can always use
    const char* const* ppArr;

    or you mean something else?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Thanks dwk. Would I be correct in saying that the issue with main mainly has to do with main being a special case?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    I don't think so. Here's why.
    Code:
    $ cat star.c
    #include <stdio.h>
    
    int main() {
        char **noconst = 0;
        const char **p = noconst;
        return 0;
    }
    $ gcc -W -Wall -ansi -pedantic -g star.c -o star
    star.c: In function `main':
    star.c:5: warning: initialization from incompatible pointer type
    star.c:5: warning: unused variable `p'
    $
    You cannot assign a char ** to a const char **. The FAQ I linked to explains why. Therefore, any function that is passed a char ** cannot be prototyped or defined to take a const char **. This is not a case special to main(). You cannot do this. The FAQ explains why better than I ever could.

    you can always use
    Code:
    const char* const* ppArr;
    or you mean something else?
    Nope . . .
    Code:
    $ cat star.c
    #include <stdio.h>
    
    int main() {
        char **noconst = 0;
        const char *const *const p = noconst;
        return 0;
    }
    $ gcc -W -Wall -ansi -pedantic -g star.c -o star
    star.c: In function `main':
    star.c:5: warning: initialization from incompatible pointer type
    star.c:5: warning: unused variable `p'
    $ # however, it does work as C++
    $ cp star.c star.cpp
    $ g++ -W -Wall -ansi -pedantic -g star.cpp -o star
    star.cpp: In function `int main()':
    star.cpp:5: warning: unused variable `const char* const* const p'
    $
    This is all explained in the FAQ I linked to.
    (C++ has more complicated rules for assigning const-qualified pointers which let you make more kinds of assignments without incurring warnings, but still protect against inadvertent attempts to modify const values. C++ would still not allow assigning a char ** to a const char **, but it would let you get away with assigning a char ** to a const char * const *.)
    I suggest you read it. It's interesting, really.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by dwks View Post
    I suggest you read it. It's interesting, really.
    I did look at the FAQ and some of these. My use of "special" is that other functions, being user defined, could further qualify the arguments. But since main is not specified any further qualified, such an option is off the table.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #12
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Yes, it seems you're right. main() is a special case.

    The thing is, I thought that const pointers-to-pointers were always a bad idea, not just when you tried to convert them to non-const pointers in various combinations . . .

    So what did you discover after reading that 52-message thread? Or one of the other ones . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 04:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21