element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Blank Arduino Sketch Uses 450 Bytes of Program Storage Space and has 9 Bytes of Global Variable?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 22 replies
  • Subscribers 396 subscribers
  • Views 3327 views
  • Users 0 members are here
  • program
  • storage
  • arduino
  • variables
Related

Blank Arduino Sketch Uses 450 Bytes of Program Storage Space and has 9 Bytes of Global Variable?

oogutierrez
oogutierrez over 10 years ago

Does anyone know why a blank Arduino Sketch Uses 450 Bytes of Program Storage Space and has 9 Bytes of Global Variable? Why?

How does this compare with other AVR compilers?

 

image

  • Sign in to reply
  • Cancel

Top Replies

  • fvan
    fvan over 10 years ago +2
    There seems to be a detailed explanation here: Analysis of an Empty Arduino Sketch Frederick
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to oogutierrez +2
    If you use the AVR Studio (I am using version 6) you see that the setup() and loop() functions can be defined to obtain the behaviour of the sketch IDE. Just the fact that you declare these functions mean…
  • mcb1
    mcb1 over 10 years ago in reply to clem57 +1
    Just to add. While the code shows nothing, there are various libraries and other settings that get compiled and sent to the board. Often its not the size of the sketch, but the libraries that take up most…
Parents
  • clem57
    clem57 over 10 years ago

    Compilers are smarter than us. If you allocate memory with no value, it is set aside and that is all. When you set a value, then a value is et in global to remember ot. No surprise to me, but I work with these for over 40 years. The loop may be optimized out of existence. I have seen this too. The behaviour is predictable IF you know how they generate code.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • oogutierrez
    oogutierrez over 10 years ago in reply to clem57

    thank you Clem, but thiss brings me back to pondering why a blank Arduino sketch would have the 9 bytes global variables when we have not used any yet.

    what are those 9 bytes for variables for?

    i wish we can compare it with other compilers or AVR IDE.

     

    i believe in other AVR IDEs it goes something like this

     

    int main(){

     

    /*main is like the setup section of arduino*/

     

    /**this is the loop section**/

    while(1)

    {

         //codes for the loop section here

    }

    /**end of loop section**/

     

     

    }

     

    if we compile this will we get similar byte usage with the Arduino.

    I am trying to understand one of the pros and cons of a given IDE.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • oogutierrez
    oogutierrez over 10 years ago in reply to oogutierrez

    I went on and try compiling an int main(), while loop in Arduino IDE and get 0 Bytes global variable and lesser program storage usage.

     

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • oogutierrez
    oogutierrez over 10 years ago in reply to oogutierrez

    Here is a comparison sketch (a version of Blink) using an int main() while loop style vs the Arduino setup() loop()... in the same Arduino IDE

     

    int main()  while loop:

    image

     

     

    Arduino setup() loop() style:

    image

     

    I don't know what is in the setup() loop() style that adds too many bytes in the program storage space. it is about double compared to using an int main() while loop.

     

     

    Another variation of the int main() while loop:

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to oogutierrez

    If you use the AVR Studio (I am using version 6) you see that the setup() and loop() functions can be defined to obtain the behaviour of the sketch IDE. Just the fact that you declare these functions mean that you need a main function entry point, a variable to manage the loop() and the two function pointer themselves for setup() and loop(). The concept is that with direct language-to-machine management you can do almost what you want while with Arduino users take advantage of some simplifications but pay this with few more memory usage due the default minimal components that are preset.

     

    As a matter of fact, it is not a low level programming, as you have the setup() and loop() functions and the relative minimal environment defined there. I am almost sure that this does not depends on the compiler itself (but the compiler may change the optimisations for sure in some cases) because with the same compiler a real C++ code written in AVR Studio generates a more compact binary than the same equivalent code with the arduino IDE.

    As far as what is my experience, this increased optimisation and reduced size of the binary will occur also using the same architecture of a "sketch" treated more seriously as a C++ source program instead of the pre-cooked version supported by the IDE.

     

     

    Enrico

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • clem57
    clem57 over 10 years ago in reply to oogutierrez

    Please select option to show all details and run these tests again. When you do you will see what code is added and  can surmise why the differences.

    clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • oogutierrez
    oogutierrez over 10 years ago in reply to balearicdynamics

    Enrico, could you please try and compile a blink program in the AVR Studio that you mentioned?

    I would like to see how many bytes it uses. Your contribution is much appreciated.

    Thanks.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • oogutierrez
    oogutierrez over 10 years ago in reply to balearicdynamics

    Enrico, could you please try and compile a blink program in the AVR Studio that you mentioned?

    I would like to see how many bytes it uses. Your contribution is much appreciated.

    Thanks.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube