Compiler Syntax Error (Newbie Question)

This is a discussion on Compiler Syntax Error (Newbie Question) within the C Programming forums, part of the General Programming Boards category; I have written my first, and what I thought was a legal, C function. This is what it looks like: ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    5

    Question Compiler Syntax Error (Newbie Question)

    I have written my first, and what I thought was a legal, C function. This is what it looks like:

    Code:
    int __fastcall testFunc(int *a1)
    {
      int result; 
      int v2; 
    
      result = *a1;
      if ( !*(_BYTE *)(*a1 + 37) )
      {
        v2 = *(_DWORD *)(result + 8);
        if ( *(_BYTE *)(v2 + 37) )
        {
          for ( result = *(_DWORD *)(result + 4); !*(_BYTE *)(result + 37); result = *(_DWORD *)(result + 4) )
          {
            if ( *a1 != *(_DWORD *)(result + 8) )
              break;
            *a1 = result;
          }
          *a1 = result;
        }
        else
        {
          for ( result = *(_DWORD *)v2; !*(_BYTE *)(result + 37); result = *(_DWORD *)result )
            v2 = result;
          *a1 = v2;
        }
      }
      return result;
    }
    I try to compile this, and I receive the following errors:

    Line 1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'testFunc'

    I think there might be some other errors in the code as well, however I guess getting the first line to work would be a start

    I am having trouble understanding the first line, since I thought that the required decorations were on the method. Can someone help me with getting this to work?

    Thanks!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,170
    Remove the __fastcall and see if it works... but it does look like correct use of __fastcall, according to my glance at MSDN documentation.

    If you really are new to C, then perhaps you should avoid what is Microsoft specific and keep to standard C.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,918
    I think calling convention declarations only need to be put on the function declarations and not definitions.
    Otherwise, it might be better to change the calling convention in the project settings. Putting them in function declarations might be useful if you're writing a dll (to make sure an application can use the exported functions even if it uses a different calling convention).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    5
    Thanks!

    I was able to get rid of that line, ran into some more errors that I am going to try to work through now.

    To be honest, I am a C# developer by trade, and am trying to pick up on C . Probably why it is littered with MSFT crap!

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    __fastcall is not a gcc keyword (there's probably some other way to "say" that you want "__fastcall", but it's not done that way.

    [Sorry if this a bit late, I got side-tracked].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    5
    Thanks so much to everyone thats replied, it really helps me learning this!

    So I was able to work through a whole lot of my errors thus far, I was missing some lack of declerations that I was able to fix by using some includes. Now, I have the code looking like this:

    Code:
    ##define _BYTE   8
    #define _DWORD  32
    
    int testFunc(int *a1)
    {
      int result; 
      int v2; 
    
      result = *a1;
      if ( !*(_BYTE *)(*a1 + 37) )
      {
        v2 = *(_DWORD *)(result + 8);
        if ( *(_BYTE *)(v2 + 37) )
        {
          for ( result = *(_DWORD *)(result + 4); !*(_BYTE *)(result + 37); result = *(_DWORD *)(result + 4) )
          {
            if ( *a1 != *(_DWORD *)(result + 8) )
              break;
            *a1 = result;
          }
          *a1 = result;
        }
        else
        {
          for ( result = *(_DWORD *)v2; !*(_BYTE *)(result + 37); result = *(_DWORD *)result )
            v2 = result;
          *a1 = v2;
        }
      }
      return result;
    }
    Now it just appears that i have some structural errors that appear to be tailored around my use of params, since I get the following:

    Line 10: error: expected expression before ')' token
    Line 12: error: expected expression before ')' token
    Line 13: error: expected expression before ')' token
    Line 15: error: expected expression before ')' token
    Line 15: error: expected expression before ')' token
    Line 15: error: expected expression before ')' token
    Line 17: error: expected expression before ')' token
    Line 25: error: expected expression before ')' token
    Line 25: error: expected expression before ')' token
    Line 25: error: expected expression before ')' token

    So, i think that perhaps I am using what is a bad example to start off for my first function, since it is appearing on each line where there is a _DWORD and _BYTE include. I thought, from my reading, that these were supposed to be used to represent integer values, like a number of bits per some type of unit. Like to calculate lengths, etc.

    Is this an inappropriate way to structure this code?

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    5
    Sorry that should have been one pound sign on the first include, I mistyped!

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you are trying to make "sized types", you will need more than the constants 8 or 32.

    Perhaps this is what you want:
    Code:
    typedef int _DWORD;
    typedef char _BYTE;
    I prefer typedef from #define, but you could do the same with #define.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    5
    Awesome! This is exactly what I needed, and actually solves a lot stuff I was running into with my previous testing. So it looks like the typedef keyword allows me to decorate a new type without actually defining a new type, that makes sense.

    I also prefer your syntax, it makes much more sense to me, as I found the use of define confusing from a readability standpoint.

    Now that I got it compiling, I am going to try to refactor this a little bit and try to make some code improvements to get a little more familiar with how I should approach these types of functions.

    Thank you so much for everyone for your help! It is super appreciated!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 12:54 PM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 09:26 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM

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