Stupid newbie question

This is a discussion on Stupid newbie question within the C Programming forums, part of the General Programming Boards category; I have recently (last week) restarted programming in C (gcc using Cygwin) after many years of Delphi programming. I am ...

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

    Stupid newbie question

    I have recently (last week) restarted programming in C (gcc using Cygwin) after many years of Delphi programming. I am busy looking through code for embedded applications, which I must maintain & develop.

    I understand the flow of most of it, but there is one reference in the makefile that I cannot understand, and no amount of googling has answered the question.

    What does this mean:

    Code:
    !include
    I know what #include is, and what it does ...

    Thanks for your patience.

  2. #2
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    #include doesn't go into makefiles...
    Are you talking about a makefile or a source file? Can you maybe post the entire line (and the ones before and after)?

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    10
    Quote Originally Posted by QuantumPete View Post
    #include doesn't go into makefiles...
    Are you talking about a makefile or a source file? Can you maybe post the entire line (and the ones before and after)?

    QuantumPete
    Erm - that's why I am confused. The file is definitely the makefile. The compiler used for this code is Borland BCC, v5.02, I believe. And it does compile, as well as make.

    Here's a few lines:

    Code:
    !include $(MAGIC_ROOT)\config.ini
    
    #CODE_SEGMENT 	= 0x4000  
    #CODE_SEGMENT 	= 0x6100  
     
    CODE_SEGMENT 	= 0x2cca  
    #CODE_SEGMENT 	= 0x2a74  
    #CODE_SEGMENT 	= 0x2b23  
    
    
    ROOT_NAME    	= APP
    SIGAPPLIB 	   = $(AM)\LIB\am_call.lib    \
                     $(AM)\LIB\pinapi.lib     \
                     $(OS)\lib\os_call.lib    \
                	  $(AM)\LIB\sgl_call.lib   \
                	  $(CTRY)\LIB\sfl_call.lib
    .
    .
    .
    .
    And there's an equally confusing exclaimation mark later on in the same code snippet:


    Code:
    # executable without debug
    $(EXE_FILE).rom : $(COMMON_LIST) $(SIGAPPLIB) $(APP_OBJ_LIST)
       $(TLINK) $(LINKOPT) @&&!
          $(APP_OBJ_LIST), $(EXE_FILE).rom, $(EXE_FILE).map, $(SIGAPPLIB) $(CC_LIB)
    !
      $(HDRTOOL) $(EXE_FILE).rom $(ROOT_NAME).ini +c
    Last edited by TimL; 05-22-2008 at 07:43 AM.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That is a makefile (or something like a makefile). It then includes a config.ini from some "magic" place.

    The principle is the same as for #include - but since # in makefiles means a comment, you couldn't use #include without breaking old makefiles (which may have #include as a comment somewhere).

    --
    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.

  5. #5
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by matsp View Post
    The principle is the same as for #include - but since # in makefiles means a comment, you couldn't use #include without breaking old makefiles (which may have #include as a comment somewhere).
    You learn something new every day.
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    10
    Quote Originally Posted by matsp View Post
    That is a makefile (or something like a makefile). It then includes a config.ini from some "magic" place.

    The principle is the same as for #include - but since # in makefiles means a comment, you couldn't use #include without breaking old makefiles (which may have #include as a comment somewhere).

    --
    Mats
    Thank you very much.

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    10
    Another stupid newbie question ...

    I'm used to Pascal/Delphi, which works well with strings.

    I have written a function to return to me the hardware platform my app is running on. The function declaration looks like this:

    Code:
    char* INIT_GetHWType(void)
    {
     char* HWType;
     do stuff
     do more stuff
     return HWType;
    }
    Somewhere else, I'd like to call this function to find out what I have got. So I do this:

    Code:
    {
       WORD              wTermStatus;
       WORD              wBankResult;
       BYTE                szPin[5];
       
    	Storage_Init();
    
    	if (INIT_GetHWType == "xyz")
    		{
    		//Set display size options here			
    	  }
    
    etc., etc., etc.
    This gives me a warning : Warning ..\source\init.c 45: Nonportable pointer comparison in function INIT_StartApp()

    So I try the following:

    Code:
    {
       WORD              wTermStatus;
       WORD              wBankResult;
       BYTE                szPin[5];
       char*               HWType;
       
    	Storage_Init();
    
            HWType = INIT_GetHWType;
    
    	if ( HWType== "xyz")
    		{
    		//Set display size options here			
    	  }
    
    etc., etc., etc.
    And this gives a compiler error.

    Error ..\source\init.c 46: Cannot convert 'char * (*)()' to 'char *' in function INIT_StartApp()

    OK, so I've googled this, and vaguely understand what the problem is. What I do not understand is: How do I assign the result of a function (which returns a string) to a variable that contains a string?

    In Pascal, I would do something like the following:

    Code:
    function MyFunction : string;
    begin
       do stuff
       result := 'stuff';
    end;
    
    procedure Callfunction
    var
        astring : string;
    begin
        astring := MyFunction;
    end;
    How do I do the same or similar in C?
    Last edited by TimL; 06-24-2008 at 03:38 AM.

  8. #8
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    You compare stringes with strcmp (INIT_GetHWType, "xyz")
    The == doesn't work on strings (pointers to char)

    And by INIT_StartApp() you mean INIT_GetHWType()??

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Actually, this
    Code:
     HWType = INIT_GetHWType;
    assigns a the INIT_GetHWType function address to HWType. The compiler moans because HWType is a pointer to char, and INIT_GetHWType is a pointer to a function that returns a char *. My guess is that you want
    Code:
     HWType = INIT_GetHWType();
    Then of course, you also need to listen to C_ntua's comments on comparing strings.

    --
    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.

  10. #10
    Registered User
    Join Date
    May 2008
    Posts
    10
    Thanks. I have found a similar problem with integers ... so your answer makes perfect sense.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by TimL View Post
    Thanks. I have found a similar problem with integers ... so your answer makes perfect sense.
    It's probably your "pascal" history that plays tricks. In Pascal, the name of a function or procedure on it's own, with no parenthesis is a valid way to call that function or procedure. In C and C++ you ALWAYS need the parenthesis, even if there's no parameters.

    I once had (what I thought was) a call to a function in some code, and I couldn't figure out why it wasn't doing what I expected. The compiler didn't give any warnings or anything - it turned out to be that I had written
    Code:
    func;
    instead of
    Code:
    func();
    Since there was no result or parameters, the compiler did just do what I told it: take the address of this function, and don't do anything with it. Which of course wasn't quite what I meant, but the compiler did exactly what I told it to do.

    --
    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.

  12. #12
    Registered User
    Join Date
    May 2008
    Posts
    10
    That sounds like what's been happening to me.

    Thanks for all your help and explainations, people.

  13. #13
    Registered User
    Join Date
    May 2008
    Posts
    10
    Yet another stupid question ...

    What does the double colon do in the following function declaration? I have looked at the Borland C++ language reference, and it talks about the "scope access operator", but I don't understand how that applies here ...

    Code:
    bool O_Comms::Init (PORT_TYPE port, COMM_PARAM_STRUCT* psComParam)

  14. #14
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    That has nothing to do with C. That is C++ and has to do with things like classes and namespaces.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid newbie question
    By CompiledMonkey in forum C++ Programming
    Replies: 6
    Last Post: 06-06-2004, 12:32 PM
  2. A very stupid newbie question
    By bradleym in forum C Programming
    Replies: 6
    Last Post: 09-14-2002, 04:08 AM
  3. Stupid Question
    By Labelizm in forum Windows Programming
    Replies: 2
    Last Post: 07-24-2002, 04:59 AM
  4. very newbie question: how to copy files
    By webwesen in forum C Programming
    Replies: 26
    Last Post: 04-25-2002, 03:01 PM
  5. Episode II Return Of the newbie : Website IO Question
    By MagiZedd in forum Windows Programming
    Replies: 1
    Last Post: 10-18-2001, 08:58 PM

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