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

How to use extern sbit declare?

I declare a variable unsigned char bdata Kde in a.c.

[in file a.c]

unsigned char bdata Kde;

Than I want to use the variable inb.c.
[in file b.c]
#include <stdio.h>
.....
extern unsigned char bdata Kde;
sbit testbit=Kde^1;
void main(void)
{......}

:error C141:.......a.c:syntax error near 'sbit'

why?

Parents
  • How hard would it be to allow the compiler to finish the job of comparing two constant expressions?

    That is not a simple question. You see, the ANSI standard from Section 6.6 states the following:

    "A constant expression can be evaluated during translation rather than runtime, and accordingly may be used in any place that a constant may be."

    So, a C Compiler may evaluate constant expressions at compile-time rather than at run-time. This is the choice of the compiler developer. It is not an optimization. Evaluating constant expressions at compile-time generates tighter code.

    There is no difference at compile-time or at run-time between (int) 1+2 and (int) 3. Both have the same value.

    The Keil compiler DOES evaluate constant expressions at compile-time. I do not know of a good quality compiler that doesn't.

    The Keil compiler DOES NOT generate code with constants evaluated explicitly at run-time. As stated previously, this is not an optimization. It is an allowed and oft-used part of the ANSI specification.

    I'm certain there are plenty of compilers that generate explicit code for each operation (constant or not, unused or not). But, I would not use them for my applications where speed and code size were important.

    Using the assembler listing generated by the compiler is a great way to help you learn the assembly language or even to help you help the compiler generate better code. But, it is not necessarily the best way to help you validate the meaning of your code. That is best done by a utility like PC-LINT (see http://www.keil.com/pclint/ ) which checks the syntax AND SYMANTECS of the program.

    Jon

Reply
  • How hard would it be to allow the compiler to finish the job of comparing two constant expressions?

    That is not a simple question. You see, the ANSI standard from Section 6.6 states the following:

    "A constant expression can be evaluated during translation rather than runtime, and accordingly may be used in any place that a constant may be."

    So, a C Compiler may evaluate constant expressions at compile-time rather than at run-time. This is the choice of the compiler developer. It is not an optimization. Evaluating constant expressions at compile-time generates tighter code.

    There is no difference at compile-time or at run-time between (int) 1+2 and (int) 3. Both have the same value.

    The Keil compiler DOES evaluate constant expressions at compile-time. I do not know of a good quality compiler that doesn't.

    The Keil compiler DOES NOT generate code with constants evaluated explicitly at run-time. As stated previously, this is not an optimization. It is an allowed and oft-used part of the ANSI specification.

    I'm certain there are plenty of compilers that generate explicit code for each operation (constant or not, unused or not). But, I would not use them for my applications where speed and code size were important.

    Using the assembler listing generated by the compiler is a great way to help you learn the assembly language or even to help you help the compiler generate better code. But, it is not necessarily the best way to help you validate the meaning of your code. That is best done by a utility like PC-LINT (see http://www.keil.com/pclint/ ) which checks the syntax AND SYMANTECS of the program.

    Jon

Children