0

I have quite complex I/O program (written by someone else) for controller ICPDAS i-7188ex and I am writing a library (.lib) for it that does some calculations based on data from that program.

Problem is, if I import function with only one line printf("123") and embed it inside I/O, program crashes at some point. Without imported function I/O works fine, same goes for imported function without I/O.

Maybe it is a memory issue but why should considerable memory be allocated for function which only outputs a string? Or I am completely wrong?

I am using Borland C++ 3.1. And yes, I can't use anything newer since controller takes only 80186 instruction set.

1 Answers1

0

If your code is complex then sometimes your compiler can get stuck and compile it wrongly messing things up with unpredictable behavior. Happen to me many times when the code grows ... In such case usually swapping few lines of code (if you can without breaking functionality) or even adding few empty or rem lines inside code sometimes helps. Problem is to find the place where it do its thing. You can also divide your program into several files compile each separately to obj and then just link them to the final file ...

The error description remembers me of one I did fight with a long time. If you are using class/struct/template try this:

may be it will help (did not test this for old turbo).

What do you mean by embed into I/O ? are you creating a sys driver file? If that is the case you need to make sure you are not messing with CPU registers. That could cause a lot of problems try to use

void some_function_or_whatever()
 {
 asm { pusha };
 // here your code
 printf("123");
 asm { popa };
 }

If you writing ISR handlers then you need to use interrupt keyword so compiler returns from it properly.

Without actual code and or MCVE is hard to point any specifics ...

If you can port this into BDS2006 or newer version (just for debug not really functional) then it will analyse your code more carefully and can detect a lot of hidden errors (was supprised when I ported from BCB series into BDS2006). Also there is CodeGuard option in the compiler which is ideal for finding such errors on runtime (but I fear you will not be able to run your lib without the I/O hw present in emulated DOS)

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Thank you for answer. Frankly speaking, I do not know low-level stuff in I/O program, main function looks like `void main() { init(); myInit(); //this is imported func, it can be small ol large while(!quit) doStuff(); RestoreCom(1); }` The thing is, the moment I add more source files, more SRAM is being used in controller (i check it via coreleft()) even if that code is not being used. At some point SRAM runs out and program crashes. – Ivan Boikov Dec 03 '16 at 16:14
  • @IvanBoikov then it could be a memory leak somewhere or just too many static variables (or even constants) have you tried to lower your heap/stack limits to match your actual memory size available ... so the compiler will throw error if you exceed what you have even before runtime... – Spektre Dec 03 '16 at 21:11