title: C->C++ Automatically cast void pointer into Type pointer in C++ in #define in case of type is not given (C-style) [MSVS]
body: <p><strong>Hi!</strong></p>
  
  <p>I've used the following <strong>C</strong> macro, But in <strong>C++</strong> it can't automatically cast <code>void*</code> to <code>type*</code>.</p>
  
  <pre><code>#define MALLOC_SAFE(var, size) { \
      var = malloc(size); \
      if (!var) goto error; \
  }
  </code></pre>
  
  <p>I know, I can do something like this:</p>
  
  <pre><code>#define MALLOC_SAFE_CPP(var, type, size) { \
      var = (type)malloc(size); \
      if (!var) goto error; \
  }
  </code></pre>
  
  <p>But I don't want to rewrite a big portion of code, where <code>MALLOC_SAFE</code> was used.</p>
  
  <p>Is there any way to do this without giving the type to the macro? Maybe some <strong>MSVC 2005</strong> <code>#pragma</code>/<code>__declspec</code>/other ?</p>
  
  <p>p.s.: I can't use C compiler, because my code is part (one of hundreds modules) of the large project. And now it's on C++. I know, I can build my code separately. But it's old code and I just want to port it fast.</p>
  
  <p>The question is about void* casting ;) If it's not possible, I'll just replace MACRO_SAFE with MACRO_SAFE_CPP</p>
  
  <p><strong>Thank You!</strong></p>