470,571 Members | 2,415 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,571 developers. It's quick & easy.

Problem with converting older C struct to VS C 7.1

Hi,
I'm in trouble here... I need to get this program working to proceed with my application.

The program is very complex, it works fine on a 10 year old system written in IBM C/2. I am showing only what I think yu may need here, please let me know if you need anything else. I am converting it to VS 7.1 (C not C++). All my source is named .C.
No compile errors, but it throws an exception at runtime. Here is the structure and the code trying to write a pointer into it. (all defined as ptrs).
Just can't seem to get a handle on why it worked in the old environment but fails now.
Expand|Select|Wrap|Line Numbers
  1. // Struct
  2.  
  3. typedef struct line
  4. {
  5.     UCHAR *index,                      // pointer to product ( in valid.file )
  6.      lineNum,                          // line # of the family
  7.      famCount;                         // number of family members
  8.  
  9. }
  10. LINE;
  11.  
  12. typedef struct win
  13. {
  14.     UCHAR *firstRecord,                // first record in file
  15.      *lastRecord,                      // last record in file
  16.      *currentRecord;                   // pointer to current record
  17.  
  18.     LINE list[FAM_MAX + 1],            // product family info
  19.      *currentFamily,                   // pointer to current ( new ) family info
  20.      *lastFamily,                      // pointer to last ( previous ) family info
  21.      *defaultFamily,                   // default product family pointer
  22.      *prepriceFamily;                  // default preprice family pointer
  23.  
  24.     UCHAR *ppfirstRecord,              // first record in pre-price validation file
  25.      *pplastRecord,                    // last record in pre-price validation file
  26.      *ppcurrentRecord;                 // pointer to current record in validation file
  27.  
  28. }
  29. WINDOW;
  30.  
  31. // Code to write a pointer ( I verified it is a good pointer vale) to the struct.
  32.  
  33. window->currentFamily->index = filePtr;
  34.  
Thanks very much for any help you can provide. I am a fairly new C programmer.
Lee
Dec 24 '07 #1
2 1456
weaknessforcats
9,208 Expert Mod 8TB
window->currentFamily->index = filePtr;
If window is null or uninitialized -> Crash
If currentFamily is null or uninitialized -> Crash

index is the same type as filePtr?? Yes? Otherwise, the code probab;y won't compile.

Now you say an exception is thrown at run time. The code you show is not going to throw an exception. Bad pointers don't do that, they just crash the program.

How do you know you have an exception condtion?? Is this C?? C doesn't have exceptions. C++ does but this code coude be either C or C++.

Maybe you could post the error.
Dec 24 '07 #2
Thanks so very much for looking at this, it is a big problem for my customer..
OK, when I run this program the message I get is:
'etspt.exe has encountered a problem and needs to close, we are sorry for any inconveinience'

then I click debug and get:
'an exception 'unhandled win32 exception has occured in etspt.exe.

etspt.exe is the main code with this code I am having problems with running as a DLL.

As far as I can tell this struct does not get initialzed, it is all pointer oriented. Yes the type being assigned is a pointer too.
Also, If i change the code to:
window->currentRecord = filePtr;

it does not get an execution error.

This all works fine inthe existing older C program.


Thanks,
Lee
Dec 24 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by vertigo | last post: by
57 posts views Thread by Xarky | last post: by
2 posts views Thread by Lorenzo | last post: by
39 posts views Thread by Martin Jørgensen | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.