EmbDev.net

Forum: ARM programming with GCC/GNU tools Pragmas in GCC


Author: Marc Khayat (zeman)
Posted on:

Rate this post
0 useful
not useful
Hi all,
I would like to investigate the use of pragmas in GCC. What are
pragmas, how are
they used, what are their limitations, and how can they be used to
carry information from
the source code to various optimizing passes. Specifically, I would
like to investigate how pragmas can be used to allocate variables to
specific memory banks.

Can anybody give me a summary, or a link to a document where I can
find such details?


Thanks!

Author: Martin Thomas (mthomas) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Marc Khayat wrote:
> Hi all,
> I would like to investigate the use of pragmas in GCC. What are
> pragmas, how are
> they used, what are their limitations, and how can they be used to
> carry information from
> the source code to various optimizing passes.

http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Pragma...

> Specifically, I would
> like to investigate how pragmas can be used to allocate variables to
> specific memory banks.

Memory-Addresses get assigned by the linker.

A possibility to place variables in a special addresse-range is to add a
section attribute with a section name to the variable declaration and
modify the linker-script to take this section into account. Make sure
the variables get initialised correclty (similar to "copy .data" and
"zero init .bss")

> Can anybody give me a summary, or a link to a document where I can
> find such details?

http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Variab...
http://sourceware.org/binutils/docs-2.17/ld/index.html

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
#pragma directives are merely arbitrary compiler directives. The can be
used for anything the author of the compiler wishes.

There is no standardisation on what directives a compiler support, and
the syntax, semantics and naming of any particular directive are
specific to the compiler and should not be expected to be portable.

The required ISO behaviour when a compiler encounters a pragma it does
not recognise is simply to ignore it - so a pragma in your code may in
fact be having no effect whatsoever if it was intended for a different
compiler.

GCC generally eschews using pragma directives altogether and very few
are supported, and then mostly for compatibility with specific compilers
to for architecture specific features. Most uses of #pragma are replaced
with function, type or variable attributes in GCC. This is a compiler
extension, but at least it will fail to compile in another compiler
rather than quietly ignoring it as it would a pragma.

Now if hopefully that is all clear, the answer to your question is in
the GCC manual (supplied with WinARM and also at
http://gcc.gnu.org/onlinedocs/), specifically the section titled
"Pragmas Accepted by GCC", section numbervaries depending on the version
5.50 in 4.2.0, and 5.49 in 4.1.2.

In general I would suggest that in GCC pragmas are not provided for any
of the purposes you have suggested in GCC.

I am not sure why you are so interested in pragmas, by definition, they
are something you only need (or want) to use in vary rare circumstances
and should be avoided wherever possible - especially in GCC.

Clifford

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.