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.

Differnces between standard C and Texas C

Hi,

I am going to move a program in Visual C++ to eZdspf28335. I was testing memory allocation with ezdspf28335 and it seems that there are differences between standard C and the C in texas DSPs, I wanted to check about the following items:

1- sizeof return the size of a variable in 16 bits.
for example if we run int f=sizeof(int);
    f  would have 1 instead of 2.

1- I wrote a small piece of code

                   int *pp[32];
                   for(int i=0;i<32;i++)
                   {
                       pp[i]=(int *)malloc(512);
                    }
It seems when we write malloc(512), it allcates 512*16 bits.
Is this true? It is different from Ansi C standard.


2- I set the heap size to 4096
          According to previous two itesm, it should mean 4096*2 Byts


3- It allocates memory in .econst memory section. Is this ok? (not in .esysmem section)

If the above is correct, is there any document about differences between C in texas DSPs and Standard C?

Thanks a lot,

   Behzad

  • Hi,

    Since the TMS320C28x char is 16 bits (to make it separately addressable), a byte is also 16 bits. Try to go through this User's Guide for more info 3666.TI_TMS320C28xOptimizingCspru514f.pdf.

    Regards,

    Igor

  • Behzad,

    The original definition of "byte" is the smallest addressable unit of data in the system. The sizeof() operator is defined such that sizeof(char) == 1. The size of a char in bits is not defined by the standard, except that it must be greater than or equal to 8. Historically, there were mainframes (and minicomputers?) that had 9-bit bytes. Today you'll mostly find the larger bytes on DSPs, which is what the C28 is.

    I recommend against using hardcoded byte sizes in any case. If you need to allocate memory (say, for an array), you can multiply by the sizeof() size of the type. For instance:

    pp[i] = (int *)malloc(32 * sizeof(int));

    Alternately, if you need a variable of a specific size, you can #include <stdint.h> and use types like int16_t and uint32_t.

    For #3, are you talking about malloc()? The memory sections are defined by the compiler. Your linker command file should take care of putting them in the right places in RAM and flash. You can find more information in SPRU514, the compiler/linker user's guide.

    Please let me know if you'd like further explanation for any of this.

  • Thanks a lot, I think I got the main point.