This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C51 v8.17a stddef.h error

In my project I include stddef.h but find error on __CX2__

it's a bug or not

I try to modify it to
#if defined (__CX2__)
and passed.

what mains about __CX2__ ?

Parents Reply Children
  • The error message is
    warning C322: unknow indentifier

    so I think the stddef.h of Ver 8.17a is error
    but other version's stddef.h is passed

    You can see Ver8.17a's stddef.h for detail

    The macro define of __CX2__ is a new iddentifier in VER8.17a

    Thanks

  • Wouldn't it have helped if you had posted this declaration?

    It obviously isn't the __CX2__ symbol that is unknown or missing, since preprocessor symbols are not unknown or missing. Just what they possibly expand to.

    Keil want me to fill in too much information for me to be interested in checking what the currently available version is.

  • Here (I think) is the fragment that the OP is talking about:

    #if __CX2__
    typedef int    ptrdiff_t;
    #else
    typedef long   ptrdiff_t;   // changed to 'long' due to 'far' pointer support
    #endif
    

    This block appears to have been added in the latest release 8.17a

  • "The error message is
    warning C322: unknow indentifier"

    That's a warning message, not an error message.

    The preprocessor should not be warning about unknown identifiers. Identifiers unknown to the preprocessor are replaced with zero (0) as the constant expression evaluated for the #if directive.

  • But I can confirm that it most certainly does!

    The following code builds with no errors & no warnings using the C51 Evaluation version 8.16a:

    #include <stdio.h>
    #include <stddef.h>
    
    void main( void )
    {
            printf( "Hello, world\r\n" );
    }
    

    After updating to the C51 Evaluation version 8.17a, the following warning is given:

    Build target 'Target 1'
    compiling main.c...
    C:\BIN\KEIL\C51\INC\STDDEF.H(21): warning C322: unknown identifier
    linking...
    Program Size: data=30.1 xdata=0 code=1080
    "Project1" - 0 Error(s), 1 Warning(s).
    

    The content of STDDEF.H in the C51 Evaluation version 8.17a, with the offending line highlighted, is:

    /*--------------------------------------------------------------------------
    STDDEF.H
    
    Standard definitions.
    Copyright (c) 1988-2004 Keil Elektronik GmbH and Keil Software, Inc.
    All rights reserved.
    --------------------------------------------------------------------------*/
    
    #ifndef __STDDEF_H__
    #define __STDDEF_H__
    
    #ifndef NULL
     #define NULL ((void *) 0)
    #endif
    
    #ifndef _SIZE_T
     #define _SIZE_T
     typedef unsigned int size_t;
    #endif
    
    #if __CX2__
    typedef int    ptrdiff_t;
    #else
    typedef long   ptrdiff_t;   // changed to 'long' due to 'far' pointer support
    #endif
    #define offsetof(s,m)   (size_t)&(((s code *)0)->m)
    
    #endif
    

    The full description of the warning message is:
    "Description The identifier in an #if directive line is undefined (evaluates to FALSE)."

    So it looks like this is an error in the updated stddef.h - the "#if" should be "#ifdef" or "#if defined"...

    Also, __CX2__ is undocumented.

  • Has any one fired off a bug report to Keil Tech Support?
    Bradford?

  • "But I can confirm that it most certainly does!"

    What is your opinion regarding whether it should or should not issue a warning in this case?

  • I accept what you say that this is a preprocessor issue - so the compiler, strictly speaking, has no business making any comment about it.

    But I think a warning here is helpful, and this particular warning has obviously been created for this very case!

    http://www.keil.com/support/man/docs/c51/c51_c322.htm

    In fact warnings 321-327 all seem to be to do with preprocessor issues...

  • They are also at the very end of the list of diagnostics - which suggests they are (relatively) new and, perhaps, relatively untested...

    Maybe this was actually a test-case for warning 322 that slipped into the release...

    ;-)

  • preprocessor issue - so the compiler, strictly speaking, has no business making any comment about it.

    Not quite, since the preprocessor is built into the compiler these days. Strictly speaking the compiler, while outputting a diagnostic about this, is the preprocessor.

  • CX2 is a new mode for SmartCards that is currently in development. The new STDLIB file accicently went into the release without carefully checking of the impact.

    Correct is:

    #ifdef __CX2__