Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9217247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:35:44+00:00 2026-06-18T02:35:44+00:00

The closest threads to my question are these Escaping a # symbol in a

  • 0

The closest threads to my question are these Escaping a # symbol in a #define macro? and How to print a pound / hash via C preprocessor?, but they don’t exactly answer my question. More explicitly, the second doesn’t seem to work with the armcc compiler; it just prints hash4 and not the symbol defined by hash. Chris Lutz was especially disparaging of trying use a macro for this functionality in the second post, so maybe this is the incorrect method all together. I would like more thoughts than just one persons, though.

The problem is the following: I’m trying to write a macro that defines an embedded asm C function utilizing a macro. I’ve essentially implemented it except for one issue… expressing an immediate value. Immediate values’ syntax requires (I believe) a pound symbol which is also the “stringify” symbol for the preprocessor. So, is it possible to escape a # symbol in a C macro?

The primary purpose behind this is to wrap an isr with a pico kernels thread context management procedures and that new procedure’s function pointer will eventually be passed to the vectored interrupt controller.

Here’s the code:

#define ISR_THREAD_MGMT(ISR_FUNC,FUNC_NAME) \
__asm void FUNC_NAME ( void ); \
__asm void FUNC_NAME (void ) \
{ \
    STMDB sp!, {r0-r3}; \
    MRS   r0, SPSR; \
    SUB   lr, lr, #4; \        <----- Heres the problem
    STMDB sp!, {r0, r10, r12, lr}; \
    bl _thread_vectored_context_save; \
    bl ISR_FUNC; \
    b _thread_context_restore; \
}

I hope I’ve explained everything in sufficient detail. If not, please don’t hesitate to ask for any more details.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:35:46+00:00Added an answer on June 18, 2026 at 2:35 am

    The second of your referenced questions shows you how to do it:

    #define hash #
    #define mash(x) x
    #define immediate(a) mash(hash)a
    #define ISR_THREAD_MGMT(ISR_FUNC,FUNC_NAME) \
    __asm void FUNC_NAME ( void ); \
    __asm void FUNC_NAME ( void ) \
    { \
        STMDB sp!, {r0-r3}; \
        MRS   r0, SPSR; \
        SUB   lr, lr, immediate(4); \
        STMDB sp!, {r0, r10, r12, lr}; \
        bl _thread_vectored_context_save; \
        bl ISR_FUNC; \
        b _thread_context_restore; \
    }
    
    ISR_THREAD_MGMT(abc,def)
    

    Output:

    # 1 "x.c"
    # 1 "<command-line>"
    # 1 "x.c"
    # 17 "x.c"
    __asm void def ( void ); __asm void def ( void ) { STMDB sp!, {r0-r3}; MRS r0, SPSR; SUB lr, lr, #4; STMDB sp!, {r0, r10, r12, lr}; bl _thread_vectored_context_save; bl abc; b _thread_context_restore; }
    

    Output reformatted:

    # 1 "x.c"
    # 1 "<command-line>"
    # 1 "x.c"
    # 17 "x.c"
    __asm void def ( void );
    __asm void def ( void )
    {
        STMDB sp!, {r0-r3};
        MRS r0, SPSR;
        SUB lr, lr, #4;
        STMDB sp!, {r0, r10, r12, lr};
        bl _thread_vectored_context_save;
        bl abc;
        b _thread_context_restore;
    }
    

    I’m not convinced it is a good idea, but it does at least work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The closest thread to my question is here . I am trying to compile
My python script creates alot of threads, they are all daemon threads, I find
I've looked at a couple of StackOverflow threads now. This comes closest. I'm stuck
There are many threads on find replace text for python but I think my
i want to target closest div from my anchor tag. so in order do
What is the closest you can get to a try-catch block in php4? I'm
parentId=$(this).closest('tr').find('td:nth(6)')[0].textContent; I am trying to get ID from flexigrid column. It works fine in
I need to search for the closest Dialcode bigger than the actual one. For
I am trying to find a closest match for a word by giving a
I am attempting to find the closest product to the given budget $array =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.