This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Mysterious C/C++ Problems

Other Parts Discussed in Thread: SYSBIOS

Hello,


I am having strange problems with my OMAP L138code.  I tried two approaches to solve the problem:

Version 1: I wrote an application in C++ (main.cpp) and it worked fine with sysbios Tasks.  But when I tried to add a HWI or timer, I got compile errors.

Version 2: To fix the problem, I started with C (main.c), put a function between my main.c and C++ files (it's also C++ but contains extern "C" so main.c has no problem with it.)  But now, I'm having mysterious problems with my fscanf function in the  C++ files.  It is the same code in Version 1, but now can't read the file properly.  It works fine in Version 1.

I'm using an OMAP L138 LCDK with sysbios 6.40.3.39 and XDC 3.30.4.52-core.


Thanks in advance,


Mike

  • Hi Mike,

    Michael Enright said:
    Version 1: I wrote an application in C++ (main.cpp) and it worked fine with sysbios Tasks.  But when I tried to add a HWI or timer, I got compile errors.

    What are the errors you are seeing?

    Michael Enright said:
    Version 2: To fix the problem, I started with C (main.c), put a function between my main.c and C++ files (it's also C++ but contains extern "C" so main.c has no problem with it.)  But now, I'm having mysterious problems with my fscanf function in the  C++ files.  It is the same code in Version 1, but now can't read the file properly.  It works fine in Version 1.

    Can you provide more details on this?  What are the issues with fscanf?

    Do you see the same issue if you use fscanf from C code?

    Steve

  • Hi Steve,

    Thank you for the reply.

    I was able to fix Version 1 by using 'extern "C" ' for any functions that are associated via the sysbios objects such as HWI, Task, etc. and still have it called main.cpp. If I created a dynamic task, there was never an isssue.

    Version 2 I gave up on since I got Version 1 to work. The problem was that the file was not being read correctly. This very same code, minus the direct filename input and character array, works fine in my other projects.

    objData::objData(std::string fname) {
    int m;
    float tmpFloat[33];

    // open data file
    //fp = fopen(fname.c_str(),"r"); // normal way I read the file from input and works with Version 1 code

    char *fname = "filename.txt"; // here I tried to input directly and use C char instead of C++ string - no luck
    fp = fopen(fname,"r"); // read mode

    if (fp == NULL) {
    System_printf("Bad file pointer for filename %s!\n", fname);
    System_flush();
    }

    // read in constant data elements
    fscanf(fp,"%d %d",&(this->int1),&(this->int2));

    .....
    }

    I haven't tried this with a C file because this processing code is resident within a C++ class.

    Thanks,


    Mike
  • I was also wondering if you could try using cin instead of fscanf.

    In any case, sounds like you got past your issue.

    Steve