Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8715167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:47:00+00:00 2026-06-13T05:47:00+00:00

In the IAR C/C++ Compiler manual, it states for writing optimization-friendly source code: Avoid

  • 0

In the IAR C/C++ Compiler manual, it states for writing optimization-friendly source code:

Avoid taking the address of local variables using the & operator. This is inefficient
for two main reasons. First, the variable must be placed in memory, and thus cannot
be placed in a processor register. This results in larger and slower code. Second, the
optimizer can no longer assume that the local variable is unaffected over function
calls.

What other methods are there of taking an address of a local variable? Obviously I know that if I had a pointer to that variable I could use that, and if I had an array I could use the array name, however I am not aware of any other methods to take the address of a local variable other than the & operator.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:47:01+00:00Added an answer on June 13, 2026 at 5:47 am

    There are no other ways to take the address[*]. The text “using the & operator” in that advice is redundant. I suppose it’s just there to remind you which operator is the address-of operator, in case you weren’t clear what you’re supposed to avoid using.

    The optimizations that it’s talking about are:

    1) if you don’t take the address, then the variable doesn’t need to have an address.

    2) if the address never “escapes” code that the compiler can see, then the compiler can assume the value doesn’t change via code that it can’t see. Not taking the address ensures this, but in some cases compilers can do escape analysis even when the address is taken.

    It really doesn’t matter for either of these purposes how the address is taken, so if there were another way to take the address in C, then the advice would have to mention it alongside the & operator.

    [*] [Edit: aha! I’m slightly wrong. If the variable is an array then you can take its address without using the & operator, just let it decay to a pointer-to-first-element. I don’t know whether or not the IAR compiler actually optimizes sufficiently small arrays into registers, if not then there’s no need to mention it. But it’s certainly allowed to.]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please refer to my code below. When optimization in IAR MSP430 compiler is set
I'm using IAR Workbench compiler with MISRA C:2004 checking on. The fragment is: #define
I am using MSP430F5418 with IAR EW 5.10 . I want to use Timer
I'm debugging some odd ARM exceptions in an embedded system using the IAR workbench
I'm using IAR Embedded Workbench for ARM (ARM7TDMI-S) and the majority of my work
IAR C/C++ Compiler for MSP430 5.10.1 [Evaluation] (5.10.1.20144) I get an illegal state internal
I have been using IAR so far, but it crashes sometimes and doesn't have
I am using MSP430F5418 wit IAR EW 5.10. In my project I am using
I am using MSP430F5418 with IAR EW 5.10. I am trying to output the
I am using boost serialization on windows, and I wanted to test my code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.