title: How to use a C struct in C++ code?
body: <p>I am trying to write a program that should use a C library (the LIS library) in a C++ program. There seems to be a problem with the creation/initialization of struct objects.</p>
  
  <p>When I run the example program on the wikipediapage: <a href="http://en.wikipedia.org/wiki/Lis_%28linear_algebra_library%29" rel="nofollow">http://en.wikipedia.org/wiki/Lis_%28linear_algebra_library%29</a> it runs like a charm, but of course that is compiled as a C program.</p>
  
  <p>In my C++ code I do it as follows:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  
  extern "C"
  {
  #include "lis.h"
  #include "lis_config.h"
      LIS_MATRIX A;
  
  }
  using namespace std;
  
  
  int main(LIS_INT argc, char* argv[])
  {
      lis_initialize(&amp;argc, &amp;argv);
      lis_matrix_create(LIS_COMM_WORLD, &amp;A);
      getchar();
  
      return 0;
  }
  </code></pre>
  
  <p>When I run this code, it gives me an access violation at the line lis_matrix_create. It seems as though A has an memory address, its data members (LIS_MATRIX is defined as a struct in Lis.h) have not been initialized, and therefore their addresses are NULL.</p>
  
  <p>Could you please tell me how to create the LIS_MATRIX in such a way that I can use it like it is done in the example code on the wikipedia page?</p>
  
  <p>Thank you in advance!</p>
  
  <p>In reply to Adam and Ross Ridge:
  I use visual studio 2013 on Windows 7 64 bit. The manual of the Lis library states that it is compatible with the Visual Studio 2008, 2010 and 2012 compilers, and also with gcc 3.4 and 4.4 and some IBM, Intel and PGI C++ compilers, I hope Visual Studio 2013 will not be a problem.</p>
  
  <p>Also, in this code, if I take out the 'extern C' block, and include 'stdio.h' instead of iostream, it runs without problems (so I guess that it means the C compiler is used?). The minute I also include iostream, the access violation start.</p>