CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: extern in macro

  1. #16
    Join Date
    Feb 2017
    Posts
    677

    Re: extern in macro

    Quote Originally Posted by TubularX View Post
    I'm using a library that provides some macros that adds overrided methods, etc.
    The library provides the macros but do you have to use them?

    If the macros change you will get compiler errors no matter what so you can as well not use them making your own code better.

  2. #17
    Join Date
    Aug 2006
    Posts
    231

    Re: extern in macro

    Quote Originally Posted by superbonzo
    if your cpp includes some headers containing a clashing name at global scope ...
    OK, I see what you mean now. I consider it low risk, but indeed, in that case I'll need to rename my class. It's not exported, though, so no big deal.

    Still, I think it will be convenient to have it in the same namespace as the rest of my code.

    Quote Originally Posted by wolle
    "If the macros change you will get compiler errors no matter what"
    There's no such guarantee.

  3. #18
    Join Date
    Feb 2017
    Posts
    677

    Re: extern in macro

    Quote Originally Posted by TubularX View Post
    There's no such guarantee.
    You could use an assertion which fails when there has been a change to a macro. If the macros are expanded in byte arrays the CRC sums of the byte arrays will be fingerprints of the macros (or the whole byte arrays could serve as fingerprints for that matter). This idea can be used to automatically detect changes to the macros. It could be part of your source code but could be external as well.

    It's a little extra work if and when the macros have been changed but maybe they are stable so it doesn't happen very often. And you do get notice also when the macros have been changed but still compile cleanly which can be a big advantage if there are strange errors. Personally I would prefer this solution rather than having to degrade my own design due to some third party library.
    Last edited by wolle; July 29th, 2017 at 09:18 AM.

  4. #19
    Join Date
    Aug 2017
    Posts
    36

    Re: extern in macro

    What you can do is define a macro in a header file and include that header in both C and C++ source files where you want to use that macro. Such a header would need to contain only code that comes from the common subset of C and C++ so it will be acceptable in both languages.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured