Size comparison of "Hello World" using C, Embedded C++ or full C++

Technical Note 11872

Targets:
ARM

Component:
Compiler

Updated:
5/10/2012 10:53 AM

Introduction

There exists a 'truth' that states 'output based on C++ source is much, much larger than output based on C source'.

It is of course true that the output is somewhat larger, but there are also strong reasons for using one of the C++ dialects.

How much memory will be used?

To compare the basic consumption of memory we have written a 'Hello World' project in all available dialects of C and C++ (using IAR Embedded Workbench for ARM version 6.xx). Download the project here.

The result looks like:

- - - C - - -

  • Compiler : ICCARM 6.10.3 
  • Language : C 
  • C dialect : C89 / C99 
  • Language conformance : Standard with IAR extensions 
  • Optimizations : Low 
  • Library Configuration : Normal 
  • printf/scanf formatters : Full 
  • // Hello World - Plain C
    #include <stdio.h>

    int main (void)
    {
    printf ("Hello World\n");

    return (0);
    } 

    8 858 bytes of readonly code memory
    54 bytes of readonly data memory
    8 712 bytes of readwrite data memory

- - - Embedded C++ - - -

  • Compiler : ICCARM 6.10.3 
  • Language : C++ 
  • C++ dialect : Embedded C++ / Extended Embedded C++ 
  • Language conformance : Standard with IAR extensions 
  • Optimizations : Low 
  • Library Configuration : Normal 
  • printf/scanf formatters : Full 
  • // Hello World - Embedded C++
    #include <iostream>

    int main (void)
    {
    cout << "Hello World" << endl;

    return (0);
    }

    8 928 bytes of readonly code memory
    252 bytes of readonly data memory
    42 644 bytes of readwrite data memory

- - - Full C++ - - -

  • Compiler : ICCARM 6.10.3 
  • Language : C++ 
  • C++ dialect : C++ (With exceptions, With RTTI) 
  • Language conformance : Standard with IAR extensions
  • Optimizations : Low
  • Library Configuration : Normal
  • printf/scanf formatters : Full
  • //Hello World - Full C++ with exceptions
    #include <iostream>

    using namespace std;

    int main (void)
    {
    try
    {
    cout << "Hello World" << endl;
    }
    catch (...)
    {
    cout << "Exception happened" << endl;
    }
    return (0);
    }

    21 963 bytes of readonly code memory
    2 637 bytes of readonly data memory
    42 680 bytes of readwrite data memory

Summary

Hello World - Plain C

8 858 bytes of readonly code memory
54 bytes of readonly data memory
8 712 bytes of readwrite data memory

Hello World - Embedded C++

8 928 bytes of readonly code memory
252 bytes of readonly data memory
42 644 bytes of readwrite data memory

Hello World - Full C++ with exceptions

21 963 bytes of readonly code memory
2 637 bytes of readonly data memory
42 680 bytes of readwrite data memory

 All product names are trademarks or registered trademarks of their respective owners.

Related Tech Notes

© IAR Systems 1995-2016 - All rights reserved.