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

  • Home
  • SEARCH
  • 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 752747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:49:02+00:00 2026-05-14T14:49:02+00:00

I am attempting to alter an IAR specific header file for a lpc2138 so

  • 0

I am attempting to alter an IAR specific header file for a lpc2138 so it can compile with Visual Studio 2008 (to enable compatible unit testing).

My problem involves converting register definitions to be hardware independent (not at a memory address)

The “IAR-safe macro” is:

#define __IO_REG32_BIT(NAME, ADDRESS, ATTRIBUTE, BIT_STRUCT) \
                    volatile __no_init ATTRIBUTE union       \
                     {                                       \
                       unsigned long NAME;                   \
                       BIT_STRUCT NAME ## _bit;              \
                     } @ ADDRESS
//declaration
//(where __gpio0_bits is a structure that names 
//each of the 32 bits as P0_0, P0_1, etc)
__IO_REG32_BIT(IO0PIN,0xE0028000,__READ_WRITE,__gpio0_bits);
//usage
IO0PIN = 0x0xAA55AA55;
IO0PIN_bit.P0_5 = 0;

This is my comparable “hardware independent” code:

#define __IO_REG32_BIT(NAME, BIT_STRUCT)\
                    volatile union \
                     {                                 \
                       unsigned long NAME;             \
                       BIT_STRUCT NAME##_bit;      \
                     } NAME;
//declaration
__IO_REG32_BIT(IO0PIN,__gpio0_bits);
//usage
IO0PIN.IO0PIN = 0xAA55AA55;
IO0PIN.IO0PIN_bit.P0_5 = 1;

This compiles and works but quite obviously my “hardware independent” usage does not match the “IAR-safe” usage.

How do I alter my macro so I can use IO0PIN the same way I do in IAR? I feel this is a simple anonymous union matter but multiple attempts and variants have proven unsuccessful. Maybe the IAR GNU compiler supports anonymous unions and vs2008 does not.

Thank you.

  • 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-05-14T14:49:02+00:00Added an answer on May 14, 2026 at 2:49 pm

    Ok folks here’s what ended up working for me:

    #define __IO_REG32_BIT(NAME, BIT_STRUCT)\
        volatile union\
        {\
            unsigned long NAME;\
            BIT_STRUCT NAME##_bit;\
        } NAME##_type;
    
    __IO_REG32_BIT(IO0PIN,__gpio0_bits);        
    
    #define IO0PIN IO0PIN_type.IO0PIN
    #define IO0PIN_bit IO0PIN_type.IO0PIN_bit
    

    Now I can use the following in my code for unit testing:

    IO0PIN = 0xFFFFFFFF;
    IO0PIN_bit.P0_5 = 1;
    

    And the preprocessor will replace it with:

    IO0PIN_type.IO0PIN = 0xFFFFFFFF;
    IO0PIN_type.IO0PIN_bit.P0_5 = 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to create a php script that can connect thru ssh to
I am attempting to compile wxWidgets 2.8.11 on Windows 7 x64 for use with
I'm attempting to use an HttpDelete object to invoke a web service's delete method.
I am attempting to deploy a Rails application (which works fine in development) onto
I'm attempting to create a client/server program, but I'm finding some difficulty continuing with
I am attempting to reorder a dynamically created list of CKEditors using the jQuery
I am attempting to create clipping mask out of a PNG with an alpha
I am attempting to get the height of an element on a page. I
I'm trying to create a dialog window using the following CSS: #blackOverlay { display:
I have a windows service that is heavily multithreaded. Each thread calls various methods

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.