Thread: Lack of variable declaration

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    5

    Lack of variable declaration

    I recently picked-up a project created by someone else and am trying to come up to speed on the code. I came across the following line of code which confuses me. The code builds just fine in CW6.3. However this is the only instance of "BOOTLOADER_VERSION" in the project. It's not even declared! Why isn't the compiler complaining about this?

    requestedData[i++]=(unsigned char)BOOTLOADER_VERSION;

    Background related info:
    This project is a combination of two seperate projects (Bootloader code & Application code). The code above was pulled from the Application project. However "BOOTLOADER_VERSION" is initialized (but still never declared) in the Bootloader project.

    This is my first experience with the CodeWarrior 6.3 IDE. Why isn't the compiler complaining when I compile the Application code?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Why isn't the compiler complaining about this?
    You seem to be confused about what CW6.3 is (an IDE - in other words, a glorified text editor) and a compiler.

    CW doesn't give a monkeys about variables, it's all just a text file.

    The real question is, which COMPILER are you using?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Novice
    Join Date
    Jul 2009
    Posts
    568
    It could be a command line define that is set somewhere in your project's configuration files. GCC, for example, has -D option that lets you define preprocessor macros. I would assume that other compiles have an equivalent option and that IDEs would make use of it.

    Code:
    #include <stdio.h>
    
    /* $ gcc source.c -DBL_VER="\"1.1.3\"" */
    
    int main(void)
    {
      printf("%s", BL_VER);  /* prints 1.1.3 */
      
      return 0;
    }
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    5
    That's sort of along the lines of what I was also assuming. However, I don't see it anywhere. Any suggestions on where to look?

    I'm using CodeWarrior 6.3 IDE.

  5. #5
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Never used it.

    There should be a possibility to see what actually gets passed to the compiler on command line. At least MS Visual Studio shows you what the complete command will be.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    I have CodeWarrior 5.9, and under the Projects menu there is a Preprocess option. It gives me a pretty serious breakdown of where every symbol from every include came from. Just make sure you're looking at the right file. It might produce a lot of crap to sift through, but hopefully will get you what you want.
    Last edited by anduril462; 01-26-2011 at 06:41 PM.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

  8. #8
    Registered User
    Join Date
    Oct 2010
    Posts
    5
    Quote Originally Posted by anduril462 View Post
    I have CodeWarrior 5.9, and under the Projects menu there is a Preprocess option. It gives me a pretty serious breakdown of where every symbol from every include came from. Just make sure you're looking at the right file. It might produce a lot of crap to sift through, but hopefully will get you what you want.
    Thanks for the tip. However, I searched and it's not in there. Any other suggestions?

    My apologies for the cross-post. I'm in quite a hurry to understand all this.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Your urgency does not make it any less rude to those who are willing to give up their time to help you when you may have found the answer elsewhere.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    It's what makes life worth living
    On the plus side, it makes it very easy to ignore posters though.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Oct 2010
    Posts
    5
    Quote Originally Posted by rags_to_riches View Post
    Your urgency does not make it any less rude to those who are willing to give up their time to help you when you may have found the answer elsewhere.
    I said I was in a hurry, not rude. Rudeness implies that I wouldn't have the basic courtesy to post my findings on this board. You assume too much...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. variable declaration within a .h file
    By stanlvw in forum C Programming
    Replies: 12
    Last Post: 12-26-2007, 11:07 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. variable type declaration
    By threahdead in forum C Programming
    Replies: 4
    Last Post: 02-27-2003, 05:45 PM
  5. Variable Declaration & Initialization :: C++
    By kuphryn in forum C++ Programming
    Replies: 6
    Last Post: 12-26-2001, 10:22 AM