1

Can any body help me to explain the impacts of PRAGMAS while i am moving 'C' files from unix (AIX/HPUX/Solaris) to Linux environment. DO we need to make any changes in order to work them fine or they will be working fine without any changes.?

Please if possible tell me the impacts which we may have to consider while porting from one environment (unix) to other (linux).

Lots of thanks in advance..

user1716079
  • 69
  • 1
  • 1
  • 9
  • in linux, i am using gcc only but in unix i am using cc/xlc compiler for C program – user1716079 Nov 01 '12 at 06:35
  • do the programs compile with gcc on the platforms you've mentioned (Solaris/HPUX/AIX). If so you shouldn't have any problems. If they don't then you do. – dave Nov 01 '12 at 07:00
  • in linux, i am using gcc only but in unix i am using cc/xlc compiler for C program.. – user1716079 Nov 01 '12 at 07:12
  • Your question is far too vague to have a real answer here. You should tell us what type of pragmas are used, and about eventual problems that you encounter with gcc on linux. BTW, when porting code to a different platform rarely the pragmas really make problems, but all the implicit assumptions that are used in the code. If you are lucky there are `#ifdef` in a central place that tune the code for the particular architecture. – Jens Gustedt Nov 01 '12 at 07:54

2 Answers2

0

This will mostly depend on your compiler. #pragmas are ignored by compilers which don't understand them. If the compiler you currently use uses some of these for the logic of the program then the program is non-portable and you'll need to change it.

dave
  • 4,812
  • 4
  • 25
  • 38
  • 1
    Compilers are not required to ignore pragmas they don't understand. They're allowed to do literally _anything_ in response to an unknown (or known) pragma. Older versions of GCC would actually launch nethack if they saw any pragmas at all. – bdonlan Nov 01 '12 at 06:25
  • That seems like a stunt from the old days of gcc. :) Often pragmas are used just to silence warnings, tune compiler-specific optimizations and the like. I have yet to see a professional compiler that doesn't ignore (possibly warning about) pragmas it doesn't understand. – user4815162342 Nov 01 '12 at 11:13
0

Pragma is part of C Standard.

The `#pragma' directive is the method specified by the C standard for providing additional information to the compiler, beyond what is conveyed in the language itself. Three forms of this directive (commonly known as pragmas) are specified by the 1999 C standard. A C compiler is free to attach any meaning it likes to other pragmas.

DO we need to make any changes in order to work them fine or they will be working fine without any changes.?
You are using different compilers. so there will be some changes required. for example GCC provides it's own pragmas,

#pragma GCC dependency
#pragma GCC poison
#pragma GCC system_header
#pragma GCC warning
#pragma GCC error

While porting to some other platform which uses different compiler then these things should be considered. I suggest you to study the compiler documentation.

Refer these discussions

Use of #pragma in C
What code have you written with #pragma you found useful?
Can anyone please tell me the use of pragma statements

Community
  • 1
  • 1
Jeyaram
  • 9,158
  • 7
  • 41
  • 63
  • in unix (AIX/IBM) i have used XLC compiler, Solaris and HP_UX, i have used simple CC compiler and in linux (where i am porting) we have used gcc compiler? So will it be fine or will it create any issue? – user1716079 Nov 01 '12 at 06:16