LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2008, 09:43 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Rep: Reputation: 32
gcc pre-compiler options !!!!!


Hello,

I have a doubt about pre-compiler.

I have defined to attributes for my variables, one for global, and one for local vars.

Quote:
#define _GLOBAL __attribute__((__weak__,__section__(".global_var")))
#define _LOCAL __attribute__((__weak__,__section__(".local_var")))
Now in my programm I can declarate my new vars:

Quote:
#include <stdio.h>
#include <stdlib.h>
#include "types_plc.h"

_GLOBAL UINT value;
_GLOBAL UINT value_2;
_LOCAL UINT value_3;
_LOCAL UINT value_4;
....
....
Now I have two new section, .global_var and .local_var.

Quote:
[24] .data PROGBITS 0804a008 001008 000008 00 WA 0 0 4
[25] .global_var PROGBITS 0804a010 001010 000004 00 WA 0 0 2
[26] .local_var PROGBITS 0804a014 001014 000004 00 WA 0 0 2
[27] .bss NOBITS 0804a018 001018 00000c 00 WA 0 0 4
But now, I would like to asign the same atributes to other vars in my project, for example:

Quote:
#include <stdio.h>
#include <stdlib.h>
#include "types_plc.h"

_GLOBAL UINT value;
_GLOBAL UINT value_2;
_LOCAL UINT value_3;
_LOCAL UINT value_4;

void prueba (void)
{
_LOCAL UINT value_1; <----- HERE IS MY PROBLEM
_LOCAL UDINT dir_1;

value_1 = 2;
dir_1 = 0;
//printf("Prueba, dir = %p.\n", dir_1);
//printf("Prueba, value_1 = %p.\n", &value_1);
}


int main(void)
{
static UDINT direccion;

value = 0;
.................
Is it possible to change attributes of this variables to allocate in other section???

best regards
 
Old 09-30-2008, 03:14 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
I don't know what you're trying to archive. Variables in the function (like the ones you have) will land on the stack or as registers (depending on the optimization). They're local and they do not belong to any section. If you made them static, the story would be different.
 
Old 09-30-2008, 03:57 PM   #3
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by Mara View Post
I don't know what you're trying to archive. Variables in the function (like the ones you have) will land on the stack or as registers (depending on the optimization). They're local and they do not belong to any section. If you made them static, the story would be different.
Hello Mara,

Sorry about my english, perhaps I did not explain well.

Then I understand that it is necessary to make them static and in this case I can put them in a section, right???

Thank you very much for your help.
Best regards

Last edited by webquinty; 10-01-2008 at 06:32 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Any leads on a pre-configured stand-alone gcc toolchain? dgandhi Programming 0 01-26-2008 12:31 PM
gcc options gobi_dgm Linux - Software 7 06-16-2006 04:54 PM
Why does GCC pre-pend ./ to my executable? halfpower Programming 7 12-14-2005 03:40 PM
GCC compiler options???!! Umanga Linux - Newbie 1 10-08-2004 03:16 AM
GCC compiler ionic Programming 3 05-10-2001 08:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration