Skip to content

request to support sdcc mcs51 declarations (__sfr, __sbit, etc) #2499

Open

Description

@zerog2k

sdcc, which is quite popular open-source, free embedded compiler, uses special extensions for intel 8051 (aka mcs51) define special function registers and other similar things (like code, ram space, etc)
e.g.

__sfr __at (0xC0) P4   ;
__sbit __at (0xC0) P4_0 ;

extensions are discussed further in section 3.5.1 of sdcc user guide:
http://sdcc.sourceforge.net/doc/sdccman.pdf

We are using sdcc for a new platformio intel-mcs51 platform, (https://github.com/platformio/platform-intel_mcs51) and would love to be able to use the vscode cpptools intellisense here to peek at register definitions, etc.

I see this was previously discussed and rejected for keil C51 compiler at #1821, however I think this is quite different in that Keil is closed/proprietary/non-free (and has it's own ide) whereas sdcc is completely free and opensource, and sdcc+platformio+vscode+cpptools are getting really close to making full open-source ide stack

tagging a few stakeholders:
Ivan Kravets (@ivankravets) Philipp Klaus Krause (@spth) Chronos (@znhocn)

Activity

  1. changed the title [-]request to support sdcc mcs51 declarations (__sfr, __sbit[/-] [+]request to support sdcc mcs51 declarations (__sfr, __sbit, etc)[/+] on Sep 7, 2018
  2. anders-liu commented on Jan 28, 2019

    @anders-liu

    Vote

  3. dimka-rs commented on Feb 3, 2019

    @dimka-rs

    Probably, STM8 interrupt case falls here too. ISR is declared this way:
    void tim4_isr(void) __interrupt(ITC_IRQ_TIM4_OVF)
    vscode expects { instead of __interrupt.

  4. wdgConsulting commented on Apr 16, 2019

    @wdgConsulting

    Similar, for SDCC STM8

    void TrapHandler (void) __trap {
    ...
    }

  5. cocus commented on May 2, 2019

    @cocus

    Hi, I would vote for the same thing. It doesn't need to be MCS51 specific; since __sfr and __at are also used in other platforms (at least, I'm using them in Z80/HD64180/Z180).

  6. leoshusar commented on May 31, 2020

    @leoshusar

    I would really appreciate this support, I am programming for SDCC and if I use void IRQHandler __interrupt() { }, it then messes up the whole document error checking.

  7. SarangKulkarni commented on Jul 18, 2020

    @SarangKulkarni

    My workaround for this is to edit .vscode/c_cpp_properties.json and edit the"defines"array so that intellisense thinks that the additional keywords are pre-processor defines. Something like:

    ...
    "defines": ["__interrupt(IntelliSense_Hack)=", ...],
    ...
    

    When you mouseover __interrupt(nn) in your actual code, you will see some garbage tooltip of
    "#define __interrupt(IntelliSense_Hack)" but that's only assumed by vscode and not by sdcc / your actual compiler, so the code compiles correctly.

  8. sean-mcmanus commented on Jul 22, 2020

    @sean-mcmanus
    Contributor

    I've filed a feature request on VS (if they add support, we would probably get it too due to shared code): https://developercommunity.visualstudio.com/idea/1122536/c-intellisense-request-to-support-sdcc-mcs51-decla.html

  9. 5 remaining items

  10. maxgerhardt commented on Mar 10, 2021

    @maxgerhardt

    Same here, upvoted this issue. I've also created a more general issue since I didn't feel the title and content wasn't general enough -- see link above.

    It would be really great to see SDCC compiler support in VSCode!

  11. anyin233 commented on Apr 1, 2021

    @anyin233

    I think I have SOLVED.
    Just #include "C:/Program Files/SDCC/include/mcs51/lint.h" and everything is wonderful =D
    If you have C:/Program Files/SDCC/** or something like that on the includePath (.vscode/c_cpp_properties.json file) you can simply use #include "mcs51/lint.h".

    Edit:
    Of course, you still have to include the header for your uC, like #include <8052.h>

    There are still some probrems with intellsense, some key words like P0_1 still cannot be determined correctly. Just like this
    image

  12. mpeschke commented on Oct 14, 2022

    @mpeschke

    When I added the sdcc include path to my project, Visual Studio Code's default c_cpp_properties.json came with a default "cStandard: c17" setting. Since sdcc itself is based on C99 (https://sdcc.sourceforge.net/), changing it to c99 satisfies Intellisense for my project files:

    image

    image

    However, it still complains about the sdcc internal implementation:

    image

    Not a solution, but a workaround until sdcc is fully supported by VSC.

  13. spth commented on Oct 16, 2022

    @spth

    Actually, the current SDCC release 4.2.0 supports C11 by default (and C17 is just a clarification of C11).

  14. onlyloveonlyu commented on Nov 4, 2022

    @onlyloveonlyu

    At present, I have achieved this through this compromise plan
    image

  15. wc7086 commented on Oct 28, 2023

    @wc7086

    Is there a patch or dirty hack that does this?

  16. GsoyG commented on Nov 30, 2023

    @GsoyG

    Is there a patch or dirty hack that does this?

    Borrow the above method:
    You can define it in the defines of c_cpp_properties.json
    image

    "__sfr=unsigned char",
    "__sbit=int",
    "__at(a)= ",
    
    __sfr __at (0x80) P0; // before
    unsigned char P0; // after
    

    This only affects IntelliSense.

  17. ultrapoci commented on Jan 30, 2024

    @ultrapoci

    I've added this configuration to my workspace:
    image

    But the keyword __interrupt is still flagged as an error:
    image

    What did I do wrong?

  18. bobbrow commented on Jan 30, 2024

    @bobbrow
    Contributor

    You will likely need to set the define as "__interrupt=" to make IntelliSense skip over it (the = is important so that it is assigned an empty string value instead of the number 1). If that still doesn't clear the error, please run the C/C++: Log Diagnostics command while the file is opened and share the output so we can determine why the define is not being used.

  19. bobbrow commented on Jan 31, 2024

    @bobbrow
    Contributor

    Nicholas Pini (@ultrapoci) I saw an update from you which seems to be deleted now (?). Based on what you said, the problem is that you are using the clangd extension for IntelliSense and it does not consider the c_cpp_properties.json configurations at all. I am not aware of a way to achieve what you want if you are using clangd for IntelliSense.

  20. ultrapoci commented on Jan 31, 2024

    @ultrapoci

    Nicholas Pini (@ultrapoci) I saw an update from you which seems to be deleted now (?). Based on what you said, the problem is that you are using the clangd extension for IntelliSense and it does not consider the c_cpp_properties.json configurations at all. I am not aware of a way to achieve what you want if you are using clangd for IntelliSense.

    Yeah, sorry, for some reason I thought I was on the clangd repo, sorry for the dumb mistake. But I've also experimented with the C/C++ extension and your suggestion worked. It was also helpful because I was able to solve the issue in clangd as well, by passing -D__interrupt flag to the compiler. Now the word is treated as an empty macro. Thank you!

  21. rushairer commented on Feb 12, 2024

    @rushairer

    Vote

  22. lgzcoollg commented on Apr 17, 2024

    @lgzcoollg

    I get the same wrong mention:
    image

    image

    when I build :

    image

    here is my setting:

    image
  23. github0null commented on Aug 13, 2025

    @github0null

    The problem can be solved by using the forceinclude function to include the following files and add a C define __VSCODE_CPPTOOL to enable it.

    https://github.com/github0null/eide/blob/master/res/data/builtin_headers/lint_sdcc.h

    Image

    I have integrated it into the plugin I developed. (https://github.com/github0null/eide)

    Image Image Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions