CrazyEngineers
  • About preprocessor statement

    vijaymp

    vijaymp

    @vijaymp-6aq6gM
    Updated: Oct 12, 2024
    Views: 914
    Why #pragma() is used in C programming? What is meant by structure padding in C programming? How is this related to pragma directive? Please do reply.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • xxxabhash007

    MemberSep 9, 2010

    When a pragma is encountered in source code, it overrides the behavior specified by the compiler option.
    Are you sure? This action cannot be undone.
    Cancel
  • anandkumarjha

    MemberSep 11, 2010

    vijaymp
    Why #pragma() is used in C programming? What is meant by structure padding in C programming? How is this related to pragma directive? Please do reply.
    _Pragma (and #pragma, which does the same sort of
    thing but with different syntax) has two effects on your
    code.
    We use #pragma or _pragma to tell the compiler something that c language can not express itself:like this function naver returns any value or it does not have any side effect
    Are you sure? This action cannot be undone.
    Cancel
  • Nupin

    MemberJul 17, 2011

    #pragma is used to execute a function before main() funtion get executed..
    visit: <a href="https://space4coder.blogspot.com/2011/07/to-execute-function-before-main.html" target="_blank" rel="nofollow noopener noreferrer">Coding Tricks: To execute a function before the main() get executed</a>
    Are you sure? This action cannot be undone.
    Cancel
  • Mallory

    MemberJul 20, 2011

    macro definitions (#define, #undef)

    To define preprocessor macros we can use #define. Its format is:
    #define identifier replacement

    When the preprocessor encounters this directive, it replaces any occurrence of identifier in the rest of the code by replacement. This replacement can be an expression, a statement, a block or simply anything. The preprocessor does not understand C++, it simply replaces any occurrence of identifier by replacement.

    #define TABLE_SIZE 100int table1[TABLE_SIZE];int table2[TABLE_SIZE];
    After the preprocessor has replaced TABLE_SIZE, the code becomes equivalent to:

    int table1[100];int table2[100];
    This use of #define as constant definer is already known by us from previous tutorials, but #define can work also with parameters to define function macros:

    #define getmax(a,b) a>b?a:b
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register