Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C++ expression evaluation.

C++ expression evaluation.

Scheduled Pinned Locked Moved C / C++ / MFC
c++combusinesstoolsperformance
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sameerkumar Namdeo
    wrote on last edited by
    #1

    Hello, consider the following program

    void main()
    {
    int tr = 0;
    int rows = 256;
    int ms = 3;
    tr += (rows & (1 << (ms - 1))) << (ms - 1);
    tr = rows & (~(1 << ms));
    }

    in above program have used only 3 integers...so can we consider that this program's memory requirement will be 3 integers (3*4 bytes). or the compiler will generate some intermediate integers for storing values of expressions like (~(1 << ms)) etc... and thus the memory requirements of this program will be more than 3 integers. i know it all depends upon how the compiler generates the code. but wanted to know the relation (w.r.t memory) between the variables declared and the intermediate expressions. Or you may please direct me to appropriate resources (forums, links)for this.. Thanks.

    My Blog.
    My codeproject Articles.

    CPalliniC L S N 4 Replies Last reply
    0
    • S Sameerkumar Namdeo

      Hello, consider the following program

      void main()
      {
      int tr = 0;
      int rows = 256;
      int ms = 3;
      tr += (rows & (1 << (ms - 1))) << (ms - 1);
      tr = rows & (~(1 << ms));
      }

      in above program have used only 3 integers...so can we consider that this program's memory requirement will be 3 integers (3*4 bytes). or the compiler will generate some intermediate integers for storing values of expressions like (~(1 << ms)) etc... and thus the memory requirements of this program will be more than 3 integers. i know it all depends upon how the compiler generates the code. but wanted to know the relation (w.r.t memory) between the variables declared and the intermediate expressions. Or you may please direct me to appropriate resources (forums, links)for this.. Thanks.

      My Blog.
      My codeproject Articles.

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      If you are using Visual Studio then you have the opportunity to see the disassembly listing (for instance via the debugger or the /FA compiler option). Other compilers may provide you this facility as well.

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • S Sameerkumar Namdeo

        Hello, consider the following program

        void main()
        {
        int tr = 0;
        int rows = 256;
        int ms = 3;
        tr += (rows & (1 << (ms - 1))) << (ms - 1);
        tr = rows & (~(1 << ms));
        }

        in above program have used only 3 integers...so can we consider that this program's memory requirement will be 3 integers (3*4 bytes). or the compiler will generate some intermediate integers for storing values of expressions like (~(1 << ms)) etc... and thus the memory requirements of this program will be more than 3 integers. i know it all depends upon how the compiler generates the code. but wanted to know the relation (w.r.t memory) between the variables declared and the intermediate expressions. Or you may please direct me to appropriate resources (forums, links)for this.. Thanks.

        My Blog.
        My codeproject Articles.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        It depends on the compiler, and the switch settings you apply. A smart compiler may toss it all out as all calculations ultimately generate a value for tr which is then not used at all. And if you were to add a function call (say print(tr);) which makes the calculations necessary, the compiler could still discover that the tr value is a constant that can be evaluated right away at compile-time, hence tossing the other variables. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
        Please use <PRE> tags for code snippets, they improve readability.
        CP Vanity has been updated to V2.4

        1 Reply Last reply
        0
        • S Sameerkumar Namdeo

          Hello, consider the following program

          void main()
          {
          int tr = 0;
          int rows = 256;
          int ms = 3;
          tr += (rows & (1 << (ms - 1))) << (ms - 1);
          tr = rows & (~(1 << ms));
          }

          in above program have used only 3 integers...so can we consider that this program's memory requirement will be 3 integers (3*4 bytes). or the compiler will generate some intermediate integers for storing values of expressions like (~(1 << ms)) etc... and thus the memory requirements of this program will be more than 3 integers. i know it all depends upon how the compiler generates the code. but wanted to know the relation (w.r.t memory) between the variables declared and the intermediate expressions. Or you may please direct me to appropriate resources (forums, links)for this.. Thanks.

          My Blog.
          My codeproject Articles.

          S Offline
          S Offline
          Sameerkumar Namdeo
          wrote on last edited by
          #4

          thanks..

          My Blog.
          My codeproject Articles.

          1 Reply Last reply
          0
          • S Sameerkumar Namdeo

            Hello, consider the following program

            void main()
            {
            int tr = 0;
            int rows = 256;
            int ms = 3;
            tr += (rows & (1 << (ms - 1))) << (ms - 1);
            tr = rows & (~(1 << ms));
            }

            in above program have used only 3 integers...so can we consider that this program's memory requirement will be 3 integers (3*4 bytes). or the compiler will generate some intermediate integers for storing values of expressions like (~(1 << ms)) etc... and thus the memory requirements of this program will be more than 3 integers. i know it all depends upon how the compiler generates the code. but wanted to know the relation (w.r.t memory) between the variables declared and the intermediate expressions. Or you may please direct me to appropriate resources (forums, links)for this.. Thanks.

            My Blog.
            My codeproject Articles.

            N Offline
            N Offline
            Niklas L
            wrote on last edited by
            #5

            In addition to previous replies, since the integers are automatic, i.e. allocated on the stack, which already has storage reserved, the memory footprint will not be affected if you add or remove such local variables, as it does not affect system resources. However, the stack will fill up quicker if you (or the compiler) add them.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups