Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving code space by altering a function call in C
    text
    copied!<p>I am calling a function that returns a variable through a pointer parameter. I do not care about the return value of this parameter <strong>nor do I want to make a dummy variable to pass to the function</strong>. For a simple example's sake, let's say the function is as follows and I don't care about, nor want to make a dummy variable for parameter "d".</p> <pre><code>void foo(int a, int b, int* c, int* d) { *c = a+b; *d = a+b+*c; } </code></pre> <p>I understand that a NULL pointer is in theory a pointer to a location that is not the address of any object or function. Would it be correct to pass NULL into "d" in this function if NULL was defined as the following? Or is this going to change whatever is at the 0'th element in memory? </p> <pre><code>#define NULL ((void *)0) </code></pre> <p>The target device is an MSP430 and I am using IAR C. <strong>No operating system is used therefore no memory management is implemented</strong></p> <p><strong>EDIT:</strong> Please note that I do not want to create a dummy variable. Also if there was a way to fool the compiler into optimizing the "d" parameter out without altering the function definition, this is preferable.</p> <p><strong>EDIT#2:</strong> I would rather not use the &amp; operator in the function call as it generates inefficient code that I do not want to generate</p> <p><strong>EDIT#3:</strong> For those who don't believe me when I am talking about the &amp; operator... the compiler manual states "Avoid taking the address of local variables using the &amp; 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."</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload