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.

warning: nonstandard conversion between pointer to function and pointer to data

Other Parts Discussed in Thread: CCSTUDIO

Hi,  I am getting this warning. how do i correct it so that, i can build the project and run it.

this below is my code for the particular line of error

  1. myconfig.dmacssal = (DMA_AdrPtr)(((Uint32)(myconfig.dmacssal)<<1)&0xFFFF);
  2. myconfig.dmacdsal = (DMA_AdrPtr)(((Uint32)(myconfig.dmacdsal)<<1)&0xFFFF);

this below is the error given out

------------------------------  hab1.pjt - Debug  ------------------------------
[main_dma1.c] "D:\CCStudio_v3.1\C5500\cgtools\bin\cl55" -g -fr"D:/Projects/hab1/Debug" -i"c:/CCStudio_v3.1" -d"CHIP_5509" -@"../../../../../../Projects/hab1/Debug.lkf" "main_dma1.c"
"main_dma1.c", line 59: warning: nonstandard conversion between pointer to function and pointer to data
"main_dma1.c", line 61: warning: nonstandard conversion between pointer to function and pointer to data

[Linking...] "D:\CCStudio_v3.1\C5500\cgtools\bin\cl55" -@"Debug.lkf"
<Linking>
>> D:\DOCUME~1\Shahid\LOCALS~1\Temp\TI6243, line 24:   error:
               can't find input file 'dsk5509bsl.lib'

>> Compilation failure

Build Complete,
  2 Errors, 2 Warnings, 0 Remarks.

  • Seems like the linker is unable to find 'dsk5509bsl.lib'. Are you sure this library is either "added" to the project, or the path to the library specified under the Linker Libraries Search path (under Build Options->Linker tab, Libraries)?

    For suppressing the compiler warnings, please see your other post: http://e2e.ti.com/support/development_tools/compiler/f/343/t/65894.aspx

  • habeeb siddique said:
    "main_dma1.c", line 59: warning: nonstandard conversion between pointer to function and pointer to data

    This warning is particularly applicable to C5500.  Function pointers and data pointers are different sizes.  Casting between them usually causes problems.  

    Thanks and regards,

    -George

     

  • Hi,

    Does this warning post a potential problem when it runs ? or it can be safely ignored ? Old CGT (v2.56 for C5510) doesn't report this warning.  

    Yuhua

  • In small memory model it is definitely a problem.  In the large model, it might work OK, but I'm not sure.  I don't know why the older compiler does not report this diagnostic.  It seems likely that it is a bug that no diagnostic is reported, and that bug has since been fixed.

    Thanks and regards,

    -George

     

  • Thanks, George,

    Do you know a fix / workaround to get rid of this warning ?

    Yuhua

  • No.  Are you building for small model or large model?

    -George

     

  • habeeb siddique said:
    1. myconfig.dmacssal = (DMA_AdrPtr)(((Uint32)(myconfig.dmacssal)<<1)&0xFFFF);

         "main_dma1.c", line 59: warning: nonstandard conversion between pointer to function and pointer to data

    I have been unable to get the compiler to generate this message.  Could you give me a little more information?

    • What compiler version?
    • Is myconfig.dmacssal declared as a pointer-to-function or pointer-to-data type?
    • Is DMA_AdrPtr a pointer-to-function or pointer-to-data type?
    • I assume Uint32 is a typedef of 'unsigned long'.  Correct?
    • What memory model are you using?

    As George has pointed out on C55x pointers to data and code have different sizes and have different meanings so converting between them can be problematic.  Data pointers are word addresses of size 16 bits (small model) or 23 bits (large model).  Code pointers are byte addresses of size 24 bits.  Conversions can be OK, but you need to take those factors into account in order to get the behavior you desire.

    Finally, if all you really want to do at this point is make that warning go away (because you know the code is OK), use -pden to get the compiler to tell you the id number of the warning, then use -pds<id> to suppress the warning.

     

  • Thanks, Paul,

    The original question was not from mine, I just happened to have the same "warning: nonstandard conversion between pointer to function and pointer to data" on the element DMACSSAL. From the answer "Function pointers and data pointers are different sizes.  Casting between them usually causes problems", in my expression, we can't do casting -- so I asked some questions. From your reply, the conversion can be OK with proper casting.  

    DMA_AdrPtr is a data type defined by TI -- "void (*DMA_AdrPtr)() pointer to a void function", I can't tell what size of address of this DMA_AdrPtr.

    In my application:

         unsigned short  g_sqDmaTxBuf[100 ];

    if I cast it with Uint32,

         (DMA_AdrPtr) (Uint32) &(g_sqDmaTxBuf[0])

    then the warning goes away, does it mean DMA_AdrPtr is 32 bits ? By the way, my application is large memory model.

     

  • This gets a bit tricky.

    Without the cast to Uint32 you are trying to convert a data pointer to a function pointer which is not allowed in C, but as an extension we allow that cast as long as the destination type is big enough to hold the source type.  In the case of C55x this is true, so we let it through but warn that this is non-standard.  (If you had compiled in strict ANSI mode (-ps) an error would have been reported.)

    With the cast to Uint32 you have two conversions, data pointer to 32-bit integer and 32-bit integer to function pointer.  The only check associated with those conversions is to see if the conversion will lose some bits.  The compiler decides no bits are lost because it compares the sizes in bytes needed to hold the values.  In these casts the answer is always 2 bytes.  But in terms of significant bits the function pointer is only 24 bits, so it seems to me the cast from 32 bits to the function pointer does lop off 8 bits and perhaps it would a good idea to issue the warning.  Of course, we are not obligated to warn you that some bits might be lost, and I'm surprised we did not.

    As far as whether it is safe to ignore the original warning (or other warnings about casts in general) it always comes down to you needing to understand what really happens and what the desired result is.  This is C, so the cast is pretty much going to let you do whatever you say you want to do.  Whether that is "right" depends on what you want.  In this case, you probably need to know that function pointers are 24-bit byte pointers and data pointers (in Large Memory Model) are 23-bit word pointers.  If converting them to each other via some integer type gets you what you want then the warning can be ignored.  But between the pointers being different sizes and addrssing different units (bytes vs words) there are a lot of ways to get what you do not want.