C coding problem
Results 1 to 5 of 5

Thread: C coding problem

  1. #1
    Senior Member
    Join Date
    Oct 2001
    Posts
    114

    C coding problem

    Hi I have a piece of code which goes like.

    union u_abc_e
    {
    t_disk_abc disk_log;
    t_xyz xyz
    };

    The file containing the above code also contains the definations pf t_disk_abc, t_xyz.

    The above code compiles fine in VC 6.0. I was trying to compile the same using MnGW and dev-c++ compiler.

    The error that I get on compilation is

    syntax error before "u_abc_e"
    syntax error before '}' token

    Now the fact that there is no syntax error in the code, as the code compiles OK with VC, makes me think that the problem is somewhere else.


    There are numerous other errors,but this is the first one of this kind.

    Most of the errors (now resolved) were because of 'stray /26 character'. There was no unix to dos file transfer, but anyways it was curious, and now has been resolved.

    Is it something to do with the C standard, I tried compiling with -ansi option, -std=c99 option and default option. The error in all the cases remains same.

    There are no library dependecy or other such issues.

    I understand that this might be a very vague problem report. Please let me know what kind of details you guys would like me to put here, and I will do the same.

    -
    Thank you.

  2. #2
    Member
    Join Date
    Jun 2003
    Posts
    41
    union u_abc_e
    {
    t_disk_abc disk_log;
    t_xyz xyz;
    };

    should get rid of the syntax error before } error.
    abt the other one, try posting a link to the full code
    Lets stop Thinking and start Drinking!

  3. #3
    Senior Member
    Join Date
    Oct 2001
    Posts
    114
    I am extremly sorry about this, since this is a proprietary code, I changed the variable names (dont wan to get in any trouble), while changng the names I accidently deleted the semi-colon.

    I will edit the code, it now becomes

    union u_abc_e
    {
    t_disk_abc disk_log;
    t_xyz xyz;
    };


    As I stated that the code compiles perfectly on VC++, I doubt there could be any actual syntax errors. I was thinkikng it has something to do with the compiler, I am pasting the compile output below (with file names changed).. The code I am woring on is huge 30-40K sloc.

    What part of it would you want, I will have to cut some part of it and modify other. Again I dont think that is very important as the problem is not with the code (compiles on other compilers - vc).


    Compiler output

    gcc.exe -c C:/temp/a.c -o C:/temp/a.o -I"F:/sw_/os/5_2_3"



    f:/common/tbl.h:741: error: syntax error before "t_disk_abc"

    f://common/tbl.h:743: error: syntax error before '}' token

    In file included from f:/amsc.h:96,
    from f:/amsc.d:46,
    from C:/temp/xxx.c:42:
    D:/Dev-Cpp/include/ctype.h:59: error: syntax error before ',' token

    In file included from f:/amsc.1d:138,
    from C:/temp/abc.c:42:
    D:/Dev-Cpp/include/string.h:36: error: syntax error before ',' token

    D:/Dev-Cpp/include/string.h:40: error: syntax error before ',' token

    D:/Dev-Cpp/include/string.h:41: error: syntax error before '*' token

    D:/Dev-Cpp/include/string.h:42: error: syntax error before ')' token

    D:/Dev-Cpp/include/string.h:45: error: syntax error before '*' token

    D:/Dev-Cpp/include/string.h:50: error: syntax error before '*' token
    .
    .
    .

    D:/Dev-Cpp/include/string.h:105: error: syntax error before '*' token

    D:/Dev-Cpp/include/string.h:106: error: syntax error before '*' token

    D:/Dev-Cpp/include/string.h:107: error: syntax error before '*' token

    D:/Dev-Cpp/include/string.h:109: error: syntax error before '*' token



    D:/Dev-Cpp/include/stdlib.h: In function `strtof':

    D:/Dev-Cpp/include/stdlib.h:314: error: `nptr' undeclared (first use in this function)
    .
    .

    D:/Dev-Cpp/include/stdlib.h:314: error: (Each undeclared identifier is reported only once

    D:/Dev-Cpp/include/stdlib.h:314: error: for each function it appears in.)

    D:/Dev-Cpp/include/stdlib.h:314: error: `endptr' undeclared (first use in this function)

    D:/Dev-Cpp/include/stdlib.h: At top level:

    .
    .
    .

    As you can see lots of errrors are in the libraries supplied by Dev-C++ (version 4.9.9.2). MinGW is 3.4.2 version.

    I have tried replacing these headers with the VC header files, but the error remains same. I will now try changing to some other minGW version.


    Its a real bummer, never have I been stuck so bad.
    Better Laugh At Your Own Problems..
    Coz...The World Laughs At Them

  4. #4
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Try to compile and link with g++ or use
    Code:
    > gcc -lstdc++
    since this looks to me like an inconsistency in the
    library generations.

    Alternatively, try to track down which libraries are
    included by sending an option to the linker via
    Code:
    >gcc -Wl,-t ... -lstdc++
    Note, I never worked with dev-cpp, hence I cannot guaranteee
    that my suggestions are related to this environment.

    Cheers
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  5. #5
    Senior Member
    Join Date
    Oct 2001
    Posts
    114
    Hi

    I did solve some of the issues here. I used -E switch to get the output after preprocessor.

    The problem with the union declaration was because I had misspelled one of the global definations passed on as compile tme arguments.

    As for the library errors, I saw the following types of output

    # 25 "D:/Dev-Cpp/include/string.h" 2
    # 36 "D:/Dev-Cpp/include/string.h"
    void* __attribute__((__cdecl__)) memchr (const void*, , size_t)

    as you can see that int here has become null. It seemed to me that this could have been caused by some #defines and indeed I found lots of #define int and undef int in the code.

    For the sake of compiling I removed all the # define int and undef int statements from the code, but the output in anycase remains the same. I.e there has been no change in the compiler output after removing all those statements.

    Seems like I am stuck again?


    Obviulsy these problems can only be found if you have the code in front of you, and have little more brain then I have

    Any other ways of tackling this?
    Better Laugh At Your Own Problems..
    Coz...The World Laughs At Them

Posting Permissions

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

 Security News

     Patches

       Security Trends

         How-To

           Buying Guides