DSPRelated.com
Forums

transplant code from VC to CCS3.1

Started by fx-7...@163.com July 26, 2010
Hello!
I'm doing a project with C6416, the project has been already worked out on the environment of Visual Studio 2008 using C++, i just want to transplant the code to the environment of CCS using C.
i change the datatype to the type defined by CCS,and change the function in "class" to the normal function.And there're a lot of question when transplanting the code.
1.in CCS,variable declaration must be ahead of any operation using these variables.but,in VS2008, it's not so strict about this.
2.the include files:the "std.h" ,error
3.No bool type? "bool is undefined"
4.No align?
5.i declare a function with parameters,but it said the parameter is
undefined...
e.g.

Bool FillInTxBufA(Uint8 *apbyTxBuf[], int volatile &nTxBufWritePos, int volatile &nTxBufReadPos)
{
....
int Temp = nTxBufWritePos;
}

error:the nTxBufWritePos is undefined?

6.i declare a array just before a function, but when i use the array in
the function, it told me the array is undefined

i was quite puzzled ,could there anyone help me, could anyone give me some tip on the transplant of C++ code from VS to CCS
appreciate your help!

_____________________________________
I don't see the specific mention of which version of CCS you are using. I'm
using 3.1.23 so your environment may be significantly different.

The biggest gotcha that I think you are running into sounds like your code
is being compiled in CCS as C code, instead of C++. I know that I use "bool"
all of the time in my CCS / Visual studio portable code, and remember
running into the bool problem early on in my development cycle. Look up what
file extensions are specific to the language for your version of the
compiler and it may simplify the porting significantly..

I can't remember what I did to make everything work correctly. I know that
in my build options for my project, on the compiler tab, and the parser
category, I've got "Embedded C++ (-pe)" checked, but don't have "Treat C
files as C++ Files (-fg)" checked. The file extension I'm using is .cpp.

On Mon, Jul 26, 2010 at 3:45 AM, wrote:

> Hello!
> I'm doing a project with C6416, the project has been already worked out on
> the environment of Visual Studio 2008 using C++, i just want to transplant
> the code to the environment of CCS using C.
> i change the datatype to the type defined by CCS,and change the function in
> "class" to the normal function.And there're a lot of question when
> transplanting the code.
> 1.in CCS,variable declaration must be ahead of any operation using these
> variables.but,in VS2008, it's not so strict about this.
> 2.the include files:the "std.h" ,error
> 3.No bool type? "bool is undefined"
> 4.No align?
> 5.i declare a function with parameters,but it said the parameter is
> undefined...
> e.g.
>
> Bool FillInTxBufA(Uint8 *apbyTxBuf[], int volatile &nTxBufWritePos, int
> volatile &nTxBufReadPos)
> {
> ....
> int Temp = nTxBufWritePos;
> }
>
> error:the nTxBufWritePos is undefined?
>
> 6.i declare a array just before a function, but when i use the array in
> the function, it told me the array is undefined
>
> i was quite puzzled ,could there anyone help me, could anyone give me some
> tip on the transplant of C++ code from VS to CCS
> appreciate your help!
>
>
Fx-

> I'm doing a project with C6416, the project has been
> already worked out on the environment of Visual Studio 2008
> using C++, i just want to transplant the code to the
> environment of CCS using C.
> i change the datatype to the type defined by CCS,and
> change the function in "class" to the normal function.And
> there're a lot of question when transplanting the code.
> 1.in CCS,variable declaration must be ahead of any
> operation using these variables.but,in VS2008, it's not so
> strict about this.
> 2.the include files:the "std.h" ,error

One general issue you have to deal with is OS. On TI C64x devices you can run no OS or DSP/BIOS. On C64x+ devices
you can also run Linux. For example, in the TI environment std.h is a DSP/BIOS header file -- so if you don't have
DSP/BIOS enabled in your project setup then you might have trouble locating some header files.

But, depending on the application, such issues might be only the tip of the iceberg. DSP/BIOS is a far away galaxy
compared with WinXP.

> 3.No bool type? "bool is undefined"

Should be defined as long as CCS recognizes the code as C++.

> 4.No align?

In TI DSP chip builds, a lot of code and data depend heavily on alignment, mainly for performance reasons but in some
cases just to get a correct result (due to VLIW, circular buffering, etc). One typical format is:

#pragma DATA_ALIGN(var, Nbytes)

You might create a macro that figures out automatically whether the code is building under VS or CCS and then invokes
alignment syntax as needed.

> 5.i declare a function with parameters,but it said
> the parameter is undefined...
> e.g.
>
> Bool FillInTxBufA(Uint8 *apbyTxBuf[], int volatile &nTxBufWritePos, int volatile &nTxBufReadPos)
> {
> ....
> int Temp = nTxBufWritePos;
> }
>
> error:the nTxBufWritePos is undefined?

Similar to 'bool' above, this looks to me like CCS is not recognizing code as C++.

-Jeff

> 6.i declare a array just before a function, but when i use the array in
> the function, it told me the array is undefined
>
> i was quite puzzled ,could there anyone help me, could anyone give me some tip on the transplant of C++ code from VS
> to CCS
> appreciate your help!

_____________________________________
thx so much for answering!
the former project on VS2008 is using C++,and the extension is .cpp. but when i'm transplanting, a senior told me that CCS doesn't support C++ quite well, so he recommend me changing the source file to the C code. i am doing so,but not so successful,i meet a lot of question as the previous text shows.how can i using the C++ parse to compile a project have both C and C++ files, a part of my porject is written by C (i use a demo of the CCS which is written in C),but the project i want to transplant is using C++.should i choose the option "treat the C file as C++"?

i'm wondering whether CCS3.1 can using class or the special synax in C++?

_____________________________________
Sorry that I missed your subject line information as to the fact that you
are running CCS3.1.

I like using the extra type control that C++ gives me over C, but I don't
know what the trade offs might really be. I know that I've mixed C and CPP
files in past projects, which causes the compiler to use the proper
semantics for each file. I recommend using the correct extension for
whichever language that you are using, it simplifies understanding what's
going on later.

Wim.

On Mon, Jul 26, 2010 at 7:34 PM, wrote:

> thx so much for answering!
> the former project on VS2008 is using C++,and the extension is .cpp. but
> when i'm transplanting, a senior told me that CCS doesn't support C++ quite
> well, so he recommend me changing the source file to the C code. i am doing
> so,but not so successful,i meet a lot of question as the previous text
> shows.how can i using the C++ parse to compile a project have both C and C++
> files, a part of my porject is written by C (i use a demo of the CCS which
> is written in C),but the project i want to transplant is using C++.should i
> choose the option "treat the C file as C++"?
>
> i'm wondering whether CCS3.1 can using class or the special synax in C++?
>
>
Fx-

> thx so much for answering!
> the former project on VS2008 is using C++,and the extension
> is .cpp. but when i'm transplanting, a senior told me
> that CCS doesn't support C++ quite well, so he recommend me
> changing the source file to the C code. i am doing
> so,but not so successful,i meet a lot of question as the
> previous text shows.

Brief comment about your "previous text": can you not cut that
text from subsequent replies? If I have to take extra time to
go back and look up a post (and my reply to it) then it's less
fun to try and help. If I feel that way then maybe other group
members feel the same -- something for you to think about.

> how can i using the C++ parse to
> compile a project have both C and C++ files, a part of my
> porject is written by C (i use a demo of the CCS which
> is written in C),but the project i want to transplant is using
> C++.should i choose the option "treat the C file as C++"?
>
> i'm wondering whether CCS3.1 can using class or the special
> synax in C++?

Not sure about CCS v3.1, but as far as I know v3.3 handles C++ (.cpp files) no problem.

If you still plan to change your C++ code to C, then I would suggest changing it under Visual Studio (VS 2008) first,
then test and verify it's working exactly same as before. Only then move to CCS. Otherwise you are changing too many
variables at once, and asking for trouble.

-Jeff

_____________________________________
hello Jeff
thx very much for giving a hand!
the #pragma DATA_ALIGN(var, Nbytes),i once used it in my other project, like this:
#pragma DATA_ALIGN(w, 8)
short w[1024*2]={.....};
but when compiling,it said that 'error: w should be const' i refer to the help file, the DATA_ALIGN is just uesd in this way.so i don't understand.
the only reason i can guessis that i use definition above in a *.h file,can #pragma be used in .h file? if it can,so why the error appear?

_____________________________________
The DATA_ALIGN() pragma has different semantics if you are working with a
C++ file from a C file. I don't know if that's part of your problem, but
it's a thought.

In my cpp file, I've got the following declaration:

#ifdef _TMS320C6X // Support for compiling on the DSP
#pragma DATA_ALIGN(8);
#endif // _TMS320C6X // Support for compiling on the DSP
float w2048[] = { /* there were 2048 values here that I chopped from the
email */};

You can see the way I've got my alignment pragma set to only be active when
I'm on the DSP platform.

Wim.

On Tue, Jul 27, 2010 at 12:37 AM, wrote:

> hello Jeff
> thx very much for giving a hand!
> the #pragma DATA_ALIGN(var, Nbytes),i once used it in my other project,
> like this:
> #pragma DATA_ALIGN(w, 8)
> short w[1024*2]={.....};
> but when compiling,it said that 'error: w should be const' i refer to the
> help file, the DATA_ALIGN is just uesd in this way.so i don't understand.
> the only reason i can guessis that i use definition above in a *.h file,can
> #pragma be used in .h file? if it can,so why the error appear?
>
>
fx,

caveat: I have not up all the details.

be sure that 'bool' is defined in the CCS C++ or the appropriate header file is
included.

std.h is probably a system file, so should be #include
however, does CCS have a std.h file? if not, then you may need to create a header file
that contains those items your code needs from the std.h file. Then include the new
header file in your code rather than the std.h. and use $include "mystd.h"

align, in CCS is a pragma, not a data modifier. Therefore the source code needs the
align pragma, immediately followed by the data declaration.

the source code will need a header file that defines such items as Uint8 and that
header file will need to be included in any source file that uses any of those macros
like Uint8.

You mention that the target language is 'C' rather than 'C++' so the function prototype
and the function declaration header will have to use '*' rather than the reference '&'
nomenclature. This means the parameters used in the call to the function will need to
use the '&' nomenclature to pass the address of the data.

I suspect the parameter 'nTxBufWritePos' is undefined because the string 'Uint8' is not
defined in an included header file.

From your comments, I suspect you need to understand the difference between a built-in
item like 'int' and a #define item like 'Int32'.

BTW:
'volatile' is a modifier, so should be before the 'type' of the variable.
(visual studio has a lot of laxity in its' syntax implementation and there are lots of
other differences between the visual studio implementation of C++ and the CCS
implementation of C++.

BTW:
'C' does not have 'class', so it will take somewhat more effort than just changing some
names to perform the port.
I would suggest using 'C++' under CCS to make the port much easier.

R. Williams

---------- Original Message -----------
From: f...@163.com
To: c...
Sent: Mon, 26 Jul 2010 06:45:53 -0400
Subject: [c6x] transplant code from VC to CCS3.1

> Hello!
> I'm doing a project with C6416, the project has been already worked
> out on the environment of Visual Studio 2008 using C++, i just want to
> transplant the code to the environment of CCS using C. i change the
> datatype to the type defined by CCS,and change the function in "class"
> to the normal function.And there're a lot of question when
> transplanting the code.
> 1.in CCS,variable declaration must be ahead of any operation using
> these variables.but,in VS2008, it's not so strict about this.
> 2.the include files:the "std.h" ,error
> 3.No bool type? "bool is undefined"
> 4.No align?
> 5.i declare a function with parameters,but it said the parameter is
> undefined...
> e.g.
>
> Bool FillInTxBufA(Uint8 *apbyTxBuf[], int volatile &nTxBufWritePos,
> int volatile &nTxBufReadPos) { .... int Temp = nTxBufWritePos; }
>
> error:the nTxBufWritePos is undefined?
>
> 6.i declare a array just before a function, but when i use the
> array in the function, it told me the array is undefined
>
> i was quite puzzled ,could there anyone help me, could anyone give me
> some tip on the transplant of C++ code from VS to CCS appreciate
> your help!
------- End of Original Message -------

_____________________________________
oops, I made an error :-( Not my first and probably not my last.

The line:
$include "mystd.h"
should be:
#include "mystd.h"

R. Williams

---------- Original Message -----------
From: "Richard Williams"
To: f...@163.com, c...
Sent: Wed, 28 Jul 2010 21:12:43 -0700
Subject: Re: [c6x] transplant code from VC to CCS3.1

> fx,
>
> caveat: I have not up all the details.
>
> be sure that 'bool' is defined in the CCS C++ or the appropriate
> header file is included.
>
> std.h is probably a system file, so should be #include
> however, does CCS have a std.h file? if not, then you may need to
> create a header file that contains those items your code needs from
> the std.h file. Then include the new header file in your code rather
> than the std.h. and use $include "mystd.h"
>
> align, in CCS is a pragma, not a data modifier. Therefore the source
> code needs the align pragma, immediately followed by the data declaration.
>
> the source code will need a header file that defines such items as
> Uint8 and that header file will need to be included in any source file
> that uses any of those macros like Uint8.
>
> You mention that the target language is 'C' rather than 'C++' so the
> function prototype and the function declaration header will have to
> use '*' rather than the reference '&' nomenclature. This means the
> parameters used in the call to the function will need to use the '&'
> nomenclature to pass the address of the data.
>
> I suspect the parameter 'nTxBufWritePos' is undefined because the
> string 'Uint8' is not defined in an included header file.
>
> >From your comments, I suspect you need to understand the difference between a built-
in
> item like 'int' and a #define item like 'Int32'.
>
> BTW:
> 'volatile' is a modifier, so should be before the 'type' of the variable.
>
> (visual studio has a lot of laxity in its' syntax implementation and
> there are lots of other differences between the visual studio
> implementation of C++ and the CCS implementation of C++.
>
> BTW:
> 'C' does not have 'class', so it will take somewhat more effort than
> just changing some names to perform the port. I would suggest using
> 'C++' under CCS to make the port much easier.
>
> R. Williams
>
> ---------- Original Message -----------
> From: f...@163.com
> To: c...
> Sent: Mon, 26 Jul 2010 06:45:53 -0400
> Subject: [c6x] transplant code from VC to CCS3.1
>
> > Hello!
> > I'm doing a project with C6416, the project has been already worked
> > out on the environment of Visual Studio 2008 using C++, i just want to
> > transplant the code to the environment of CCS using C. i change the
> > datatype to the type defined by CCS,and change the function in "class"
> > to the normal function.And there're a lot of question when
> > transplanting the code.
> > 1.in CCS,variable declaration must be ahead of any operation using
> > these variables.but,in VS2008, it's not so strict about this.
> > 2.the include files:the "std.h" ,error
> > 3.No bool type? "bool is undefined"
> > 4.No align?
> > 5.i declare a function with parameters,but it said the parameter is
> > undefined...
> > e.g.
> >
> > Bool FillInTxBufA(Uint8 *apbyTxBuf[], int volatile &nTxBufWritePos,
> > int volatile &nTxBufReadPos) { .... int Temp = nTxBufWritePos; }
> >
> > error:the nTxBufWritePos is undefined?
> >
> > 6.i declare a array just before a function, but when i use the
> > array in the function, it told me the array is undefined
> >
> > i was quite puzzled ,could there anyone help me, could anyone give me
> > some tip on the transplant of C++ code from VS to CCS appreciate
> > your help!
> ------- End of Original Message -------
------- End of Original Message -------

_____________________________________