Declaring and initializing same variable but with different datatypes based on conditional statements in C
<p>I have to use same variable name with different user define datatypes.</p>

<p>Eg.</p>

<pre><code>if (scan = NEAR)
{
  Near_t p_Data = getData()-&gt;Near;
}
else if (scan == FAR)
{
  Far_t p_Data = getData()-&gt;Far;
}

Data_1 = p_Data-&gt;d1;
Data_2 = p_Data-&gt;d2;
</code></pre>

<p>Thus I want to eliminate the repetitive code for different datatypes.
In the above manner, it throws error since declaration is within the scope of conditional statement &amp; also redefinition is happened
How to achieve this functionality otherwise?</p>