Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #43727 > unrolled thread
| Started by | Ralph Doncaster <ralphdoncaster@gmail.com> |
|---|---|
| First post | 2014-04-28 13:53 -0700 |
| Last post | 2014-04-28 19:57 -0700 |
| Articles | 17 — 11 participants |
Back to article view | Back to comp.lang.c
can linker symbols be defined in C? Ralph Doncaster <ralphdoncaster@gmail.com> - 2014-04-28 13:53 -0700
Re: can linker symbols be defined in C? James Kuyper <jameskuyper@verizon.net> - 2014-04-28 17:15 -0400
Re: can linker symbols be defined in C? Andrew Smallshaw <andrews@sdf.lonestar.org> - 2014-04-28 21:17 +0000
Re: can linker symbols be defined in C? Keith Thompson <kst-u@mib.org> - 2014-04-28 14:53 -0700
Re: can linker symbols be defined in C? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-04-28 23:28 +0000
Re: can linker symbols be defined in C? James Kuyper <jameskuyper@verizon.net> - 2014-04-28 18:01 -0400
Re: can linker symbols be defined in C? jacob navia <jacob@spamsink.net> - 2014-04-29 00:26 +0200
Re: can linker symbols be defined in C? "Bill Cunningham" <nospam@nspam.invalid> - 2014-04-28 19:39 -0400
Re: can linker symbols be defined in C? Ian Collins <ian-news@hotmail.com> - 2014-04-29 11:45 +1200
Re: can linker symbols be defined in C? Ralph Doncaster <ralphdoncaster@gmail.com> - 2014-04-28 20:15 -0700
Re: can linker symbols be defined in C? Kaz Kylheku <kaz@kylheku.com> - 2014-04-29 04:11 +0000
Re: can linker symbols be defined in C? Ralph Doncaster <ralphdoncaster@gmail.com> - 2014-04-29 16:29 -0700
Re: can linker symbols be defined in C? Noob <root@127.0.0.1> - 2014-04-29 08:33 +0200
Re: can linker symbols be defined in C? Siri Crews <chine.bleu@yahoo.com> - 2014-04-28 16:54 -0700
Re: can linker symbols be defined in C? Ralph Doncaster <ralphdoncaster@gmail.com> - 2014-04-28 20:01 -0700
Re: can linker symbols be defined in C? Kaz Kylheku <kaz@kylheku.com> - 2014-04-29 00:20 +0000
Re: can linker symbols be defined in C? Ralph Doncaster <ralphdoncaster@gmail.com> - 2014-04-28 19:57 -0700
| From | Ralph Doncaster <ralphdoncaster@gmail.com> |
|---|---|
| Date | 2014-04-28 13:53 -0700 |
| Subject | can linker symbols be defined in C? |
| Message-ID | <2231b9bc-305e-4ed5-af87-e203dd64780a@googlegroups.com> |
I want to define linker symbols in C. I can do it using gcc inline assembler:
#define STR1(x) #x
#define STR(x) STR1(x)
... more macros that calculate TXDELAYCOUNT
asm(".global TXDELAY" );
asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
Is there a way to do the same thing in standard C11?
[toc] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2014-04-28 17:15 -0400 |
| Message-ID | <535EC4F0.9010504@verizon.net> |
| In reply to | #43727 |
On 04/28/2014 04:53 PM, Ralph Doncaster wrote:
> I want to define linker symbols in C. I can do it using gcc inline assembler:
> #define STR1(x) #x
> #define STR(x) STR1(x)
> ... more macros that calculate TXDELAYCOUNT
> asm(".global TXDELAY" );
> asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>
>
> Is there a way to do the same thing in standard C11?
The only way that standard C provides for defining symbols that are
meaningful to the linker is by defining identifiers for objects or
functions with external linkage; C2011 doesn't change that.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Smallshaw <andrews@sdf.lonestar.org> |
|---|---|
| Date | 2014-04-28 21:17 +0000 |
| Message-ID | <slrn3vfsllthbi.b9a.andrews@sdf.lonestar.org> |
| In reply to | #43727 |
On 2014-04-28, Ralph Doncaster <ralphdoncaster@gmail.com> wrote:
> I want to define linker symbols in C. I can do it using gcc inline assembler:
> #define STR1(x) #x
> #define STR(x) STR1(x)
> ... more macros that calculate TXDELAYCOUNT
> asm(".global TXDELAY" );
> asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>
>
> Is there a way to do the same thing in standard C11?
No. The C standards don't even explicitly acknowledge the existence
of a linker (references to "compiliation units" are the nearest
you get), never mind providing a method of providing what are
inevitably platform-specific directions to it.
--
Andrew Smallshaw
andrews@sdf.lonestar.org
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2014-04-28 14:53 -0700 |
| Message-ID | <ln61ltp1ci.fsf@nuthaus.mib.org> |
| In reply to | #43735 |
Andrew Smallshaw <andrews@sdf.lonestar.org> writes:
> On 2014-04-28, Ralph Doncaster <ralphdoncaster@gmail.com> wrote:
>> I want to define linker symbols in C. I can do it using gcc inline
>> assembler:
>> #define STR1(x) #x
>> #define STR(x) STR1(x)
>> ... more macros that calculate TXDELAYCOUNT
>> asm(".global TXDELAY" );
>> asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>>
>>
>> Is there a way to do the same thing in standard C11?
>
> No. The C standards don't even explicitly acknowledge the existence
> of a linker (references to "compiliation units" are the nearest
> you get), never mind providing a method of providing what are
> inevitably platform-specific directions to it.
In fact the C standard does describe linking, though it doesn't refer to
a "linker" as the tool that does it.
N1570 5.1.1.2 describes linking as the 8th and final translation phase:
All external object and function references are resolved. Library
components are linked to satisfy external references to functions
and objects not defined in the current translation. All such
translator output is collected into a program image which
contains information needed for execution in its execution
environment.
But you're correct that the C standard doesn't provide a way to define
linker symbols.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | glen herrmannsfeldt <gah@ugcs.caltech.edu> |
|---|---|
| Date | 2014-04-28 23:28 +0000 |
| Message-ID | <ljmo62$8rb$2@speranza.aioe.org> |
| In reply to | #43749 |
Keith Thompson <kst-u@mib.org> wrote: (snip) > In fact the C standard does describe linking, though it doesn't refer to > a "linker" as the tool that does it. > N1570 5.1.1.2 describes linking as the 8th and final translation phase: > All external object and function references are resolved. Library > components are linked to satisfy external references to functions > and objects not defined in the current translation. All such > translator output is collected into a program image which > contains information needed for execution in its execution > environment. > But you're correct that the C standard doesn't provide a way to define > linker symbols. The Linkers I am used to also don't describe "linker symbols" but instead "external symbols". (I suppose linker symbols could be names for the symbols inside the linker, that is, in the linker source program. Most often, one can ignore them.) C does provide ways to generate external symbols. -- glen
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Date | 2014-04-28 18:01 -0400 |
| Message-ID | <535ECFA6.5040500@verizon.net> |
| In reply to | #43735 |
On 04/28/2014 05:17 PM, Andrew Smallshaw wrote: ... > No. The C standards don't even explicitly acknowledge the existence > of a linker (references to "compiliation units" are the nearest > you get), never mind providing a method of providing what are > inevitably platform-specific directions to it. The standard mentions linkers in footnote 71 (n1570.pdf): "On systems in which linkers cannot accept extended characters, an encoding of the universal character name may be used in forming valid external identifiers.". This is a non-normative footnote, and describes a very specific special case, so it doesn't count for much. "The separate translation units of a program communicate by (for example) calls to functions whose identifiers have external linkage, manipulation of objects whose identifiers have external linkage ... Translation units may be separately translated and then later linked to produce an executable program." (5.1.1.1p1) The standard does not require that a separate program handle that process. However, if such a program is used, it seems to me to be reasonable to use the term "linker" to refer to it. I think it still makes sense to describe the part of the implementation that handles linking together translation units as the "linker", even if it isn't actually a separate program. "In the set of translation units and libraries that constitutes an entire program, each declaration of a particular identifier with external linkage denotes the same object or function." (6.2.2p2) Those three citations seems to me to be more than enough to qualify as "explicitly acknowledging the existence of a linker". They don't do much more than acknowledging it, and there's not much more in the rest of the standard about linking. The rules about how external linkage works imply some constraints on how a linker could be implemented, but no details are given.
[toc] | [prev] | [next] | [standalone]
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Date | 2014-04-29 00:26 +0200 |
| Message-ID | <ljmkji$298$1@speranza.aioe.org> |
| In reply to | #43727 |
Le 28/04/2014 22:53, Ralph Doncaster a écrit :
> I want to define linker symbols in C. I can do it using gcc inline assembler:
> #define STR1(x) #x
> #define STR(x) STR1(x)
> ... more macros that calculate TXDELAYCOUNT
> asm(".global TXDELAY" );
> asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>
>
> Is there a way to do the same thing in standard C11?
>
hi ralph
What about
char *TXDELAY = STR(TXDELAYCOUNT);
if the macros expand into a character string (with quotes).
If the macros expand into an integer you do
int TXDELAY = STR(TXDELAYCOUNT);
In general the compiler emits a .globl for each global name.
THE CATCH
---------
In C you can do this ONCE. Once you have set the value to something you
can't change it duringthe compilation.
For instance this is NOT ALLOWED:
int TXDELAY = 56;
... some code ...
int TXDELAY 967;
This is NOT allowed in C, but allowed in the gcc assembler! BEWARE.
If you only set TXDELAY ONCE you can write it in C. If you change it
several times in the program you can't do that in C and you should stick
to inline assembly.
BUT
Is it good software practice to do that?
Do YOU really know what value is used for TXDELAY after 6 changes in the
code?
The usage of .equ in this form is really a hack. Try to use different
identifier and stick to C.
You CAN do the same using the preprocessor however.
#define TXDELAY 25
... code ...
#undef TXDELAY
#define TXDELAY 250
... code
#undef TXDELAY
etc. But that is as a bad hack as asm(".equ ...");
Note that TXDELAY goes into the executable as a global variable and the
value stored into the variable is the LAST value used. Did you know that?
Is THAT really what you want?
jacob
P.S. Sorry for all the guys citing the C standard. They can't do
anything else. But not all people here are like that.
[toc] | [prev] | [next] | [standalone]
| From | "Bill Cunningham" <nospam@nspam.invalid> |
|---|---|
| Date | 2014-04-28 19:39 -0400 |
| Message-ID | <ljmos4$ci6$1@dont-email.me> |
| In reply to | #43760 |
"jacob navia" <jacob@spamsink.net> wrote in message
news:ljmkji$298$1@speranza.aioe.org...
> Le 28/04/2014 22:53, Ralph Doncaster a écrit :
>> I want to define linker symbols in C. I can do it using gcc inline
>> assembler:
>> #define STR1(x) #x
>> #define STR(x) STR1(x)
>> ... more macros that calculate TXDELAYCOUNT
>> asm(".global TXDELAY" );
>> asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>>
>>
>> Is there a way to do the same thing in standard C11?
>>
> hi ralph
>
> What about
>
> char *TXDELAY = STR(TXDELAYCOUNT);
>
> if the macros expand into a character string (with quotes).
>
> If the macros expand into an integer you do
>
> int TXDELAY = STR(TXDELAYCOUNT);
>
> In general the compiler emits a .globl for each global name.
>
> THE CATCH
> ---------
>
> In C you can do this ONCE. Once you have set the value to something you
> can't change it duringthe compilation.
>
> For instance this is NOT ALLOWED:
>
> int TXDELAY = 56;
>
> ... some code ...
>
> int TXDELAY 967;
>
> This is NOT allowed in C, but allowed in the gcc assembler! BEWARE.
>
> If you only set TXDELAY ONCE you can write it in C. If you change it
> several times in the program you can't do that in C and you should stick
> to inline assembly.
>
> BUT
>
> Is it good software practice to do that?
>
> Do YOU really know what value is used for TXDELAY after 6 changes in the
> code?
>
> The usage of .equ in this form is really a hack. Try to use different
> identifier and stick to C.
>
> You CAN do the same using the preprocessor however.
>
> #define TXDELAY 25
> ... code ...
> #undef TXDELAY
>
> #define TXDELAY 250
> ... code
> #undef TXDELAY
>
> etc. But that is as a bad hack as asm(".equ ...");
>
> Note that TXDELAY goes into the executable as a global variable and the
> value stored into the variable is the LAST value used. Did you know that?
>
> Is THAT really what you want?
>
> jacob
>
> P.S. Sorry for all the guys citing the C standard. They can't do anything
> else. But not all people here are like that.
You're spamming! You're in every thread!
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2014-04-29 11:45 +1200 |
| Message-ID | <bs87h2F66euU1@mid.individual.net> |
| In reply to | #43760 |
jacob navia wrote: > > P.S. Sorry for all the guys citing the C standard. They can't do > anything else. But not all people here are like that. Nice :) Some people don't live in the real world. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Ralph Doncaster <ralphdoncaster@gmail.com> |
|---|---|
| Date | 2014-04-28 20:15 -0700 |
| Message-ID | <7ccde203-5790-4bde-8b18-1e93028f0e65@googlegroups.com> |
| In reply to | #43760 |
On Monday, 28 April 2014 19:26:57 UTC-3, jacob navia wrote:
> Le 28/04/2014 22:53, Ralph Doncaster a écrit :
>
> > I want to define linker symbols in C. I can do it using gcc inline assembler:
>
> > #define STR1(x) #x
>
> > #define STR(x) STR1(x)
>
> > ... more macros that calculate TXDELAYCOUNT
>
> > asm(".global TXDELAY" );
>
> > asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>
> >
>
> >
>
> > Is there a way to do the same thing in standard C11?
>
> >
> Note that TXDELAY goes into the executable as a global variable and the
>
> value stored into the variable is the LAST value used. Did you know that?
Yes, that is exactly what I want, and it's only defined once (in my header file).
http://code.google.com/p/nerdralph/source/browse/trunk/avr/BBUart.h
The defined values are used in my asm file:
http://code.google.com/p/nerdralph/source/browse/trunk/avr/BBUart.S
My previous solution involved adding an extra parameter to TxByte and 2 extra parameters to RxByte which contained the timing values. Having them defined linker symbols is much cleaner (smaller code size, and more readable).
[toc] | [prev] | [next] | [standalone]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Date | 2014-04-29 04:11 +0000 |
| Message-ID | <20140428210345.244@kylheku.com> |
| In reply to | #43801 |
On 2014-04-29, Ralph Doncaster <ralphdoncaster@gmail.com> wrote:
> On Monday, 28 April 2014 19:26:57 UTC-3, jacob navia wrote:
>> Le 28/04/2014 22:53, Ralph Doncaster a écrit :
>>
>> > I want to define linker symbols in C. I can do it using gcc inline assembler:
>>
>> > #define STR1(x) #x
>>
>> > #define STR(x) STR1(x)
>>
>> > ... more macros that calculate TXDELAYCOUNT
>>
>> > asm(".global TXDELAY" );
>>
>> > asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>>
>> >
>>
>> >
>>
>> > Is there a way to do the same thing in standard C11?
>>
>> >
>
>> Note that TXDELAY goes into the executable as a global variable and the
>>
>> value stored into the variable is the LAST value used. Did you know that?
>
> Yes, that is exactly what I want, and it's only defined once (in my header file).
> http://code.google.com/p/nerdralph/source/browse/trunk/avr/BBUart.h
> The defined values are used in my asm file:
> http://code.google.com/p/nerdralph/source/browse/trunk/avr/BBUart.S
I was about to say that you can have your assembly sources preprocessed
in GNU toolchains, but there you go.
Why don't you do the above stuff with TXDELAYCOUNT in the .S file?
Then you don't need the STR() hack, because you're not dealing with
inline assembler.
[toc] | [prev] | [next] | [standalone]
| From | Ralph Doncaster <ralphdoncaster@gmail.com> |
|---|---|
| Date | 2014-04-29 16:29 -0700 |
| Message-ID | <7ce23c86-2262-47ae-abeb-7acdb4a72c09@googlegroups.com> |
| In reply to | #43803 |
On Tuesday, 29 April 2014 01:11:54 UTC-3, Kaz Kylheku wrote: > Why don't you do the above stuff with TXDELAYCOUNT in the .S file? > > Then you don't need the STR() hack, because you're not dealing with > > inline assembler. So it's easier for other people to use with their code. BBUart.S and BBUart.h don't get changed - the user just defines BAUD_RATE (if they want something other than 57600), and includes BBUart.h in their .c file.
[toc] | [prev] | [next] | [standalone]
| From | Noob <root@127.0.0.1> |
|---|---|
| Date | 2014-04-29 08:33 +0200 |
| Message-ID | <ljnh3e$6ku$1@dont-email.me> |
| In reply to | #43801 |
Ralph Doncaster wrote: > Yes, that is exactly what I want, and it's only defined once (in my header file). > http://code.google.com/p/nerdralph/source/browse/trunk/avr/BBUart.h > The defined values are used in my asm file: > http://code.google.com/p/nerdralph/source/browse/trunk/avr/BBUart.S > > My previous solution involved adding an extra parameter to TxByte and > 2 extra parameters to RxByte which contained the timing values. > Having them defined linker symbols is much cleaner (smaller code > size, and more readable). Try also asking in comp.arch.embedded, you might get a few useful suggestions. Regards.
[toc] | [prev] | [next] | [standalone]
| From | Siri Crews <chine.bleu@yahoo.com> |
|---|---|
| Date | 2014-04-28 16:54 -0700 |
| Message-ID | <chine.bleu-C67D75.16540628042014@news.eternal-september.org> |
| In reply to | #43727 |
In article <2231b9bc-305e-4ed5-af87-e203dd64780a@googlegroups.com>,
Ralph Doncaster <ralphdoncaster@gmail.com> wrote:
> I want to define linker symbols in C. I can do it using gcc inline assembler:
> #define STR1(x) #x
> #define STR(x) STR1(x)
> ... more macros that calculate TXDELAYCOUNT
> asm(".global TXDELAY" );
> asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>
>
> Is there a way to do the same thing in standard C11?
No. You can use C as an interpretted language that runs out of the parser with
no compilation or linking.
You can do it in most implementations that use a linker (like the unix ld) with
a linker directive to equate an external symbol to an absolute address.
extern int externalsymbol;
static int externalvalue = (intptr_t)&externalsymbol;
--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted.
'I desire mercy, not sacrifice.'
Icke's razor: Given two equally plausible explanations, choose the weirder.
[toc] | [prev] | [next] | [standalone]
| From | Ralph Doncaster <ralphdoncaster@gmail.com> |
|---|---|
| Date | 2014-04-28 20:01 -0700 |
| Message-ID | <f36c0cf3-3388-45c1-ac8e-bc7ba4036eb8@googlegroups.com> |
| In reply to | #43787 |
On Monday, 28 April 2014 20:54:14 UTC-3, Siri Crews wrote:
> Ralph Doncaster wrote:
>
>
>
> > I want to define linker symbols in C. I can do it using gcc inline assembler:
>
> > #define STR1(x) #x
>
> > #define STR(x) STR1(x)
>
> > ... more macros that calculate TXDELAYCOUNT
>
> > asm(".global TXDELAY" );
>
> > asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>
> >
>
> >
>
> > Is there a way to do the same thing in standard C11?
>
>
>
> No. You can use C as an interpretted language that runs out of the parser with
>
> no compilation or linking.
>
>
>
> You can do it in most implementations that use a linker (like the unix ld) with
>
> a linker directive to equate an external symbol to an absolute address.
>
>
>
> extern int externalsymbol;
>
> static int externalvalue = (intptr_t)&externalsymbol;
>
If you mean gcc linker scripts, I've never used them before. It sounds like more work than the asm statements, and still doesn't make it portable.
[toc] | [prev] | [next] | [standalone]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Date | 2014-04-29 00:20 +0000 |
| Message-ID | <20140428170342.745@kylheku.com> |
| In reply to | #43727 |
On 2014-04-28, Ralph Doncaster <ralphdoncaster@gmail.com> wrote:
> I want to define linker symbols in C. I can do it using gcc inline assembler:
> #define STR1(x) #x
> #define STR(x) STR1(x)
> ... more macros that calculate TXDELAYCOUNT
> asm(".global TXDELAY" );
> asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
Okay, so here we calculate a name somehow (perhaps based on some
platform configuration preprocessor symbols) and make TXDELAY
and alias for that symbol.
There are less direct ways to do that, which are very portable. E.g.
/* header */
extern delay_t *tx_delay_loc;
#define tx_delay (*tx_delay_loc)
/* platform-specific .c file */
delay_t *tx_delay_loc = <platform specific value>;
Or, if it can't be statically determined, the module init routine
could do it:
void board_init(void)
{
tx_delay_loc = <whatever>;
}
If the location is simple constant memory address, it can be something like:
#if CONFIG_SUCH_AND_SUCH
#define tx_delay_loc_inline = ((unsigned long *) SUCH_AND_SUCH_TX_DELAY_REG)
#elif CONFIG_OTHER
...
#endif
#define tx_delay (*tx_delay_loc_inline)
These techniques are not incompatible with doing it using toolchain-specific
linker tricks also, on some of the targets where that is an option.
In C++ you can abuse a reference to create an alias:
static delay_t &tx_delay = *tx_delay_loc_inline;
Or, perhaps, not abuse them at all:
#if CONFIG_SUCH_AND_SUCH
/* assuming Such and Such platform has a declared SUCH_AND_SUC_TX_DELAY
as a global variable of type long */
static long &tx_delay = SUCH_AND_SUCH_TX_DELAY;
#endif
I.e. C++ references at file scope de facto provide a similar capability to
linker-level symbol aliasing (at least for objects, not functions).
[toc] | [prev] | [next] | [standalone]
| From | Ralph Doncaster <ralphdoncaster@gmail.com> |
|---|---|
| Date | 2014-04-28 19:57 -0700 |
| Message-ID | <148930f1-9756-43d8-9a3e-55ea7bc211b1@googlegroups.com> |
| In reply to | #43791 |
On Monday, 28 April 2014 21:20:00 UTC-3, Kaz Kylheku wrote:
> On 2014-04-28, Ralph Doncaster <ralphdoncaster> wrote:
>
> > I want to define linker symbols in C. I can do it using gcc inline assembler:
>
> > #define STR1(x) #x
>
> > #define STR(x) STR1(x)
>
> > ... more macros that calculate TXDELAYCOUNT
>
> > asm(".global TXDELAY" );
>
> > asm(".equ TXDELAY, " STR(TXDELAYCOUNT) );
>
> /* header */
>
> extern delay_t *tx_delay_loc;
>
> #define tx_delay (*tx_delay_loc)
>
>
>
> /* platform-specific .c file */
>
> delay_t *tx_delay_loc = <platform specific value>;
I haven't tried the code, but it looks like it's going to create global variable, i.e. that gets initialized in the bss. The asm code I showed doesn't take any space at runtime. The target platform code I've written in AVR assembler, and gets substituted into a "ldi register, TXDELAY" instruction. If I used a global variable it would get initialized in gcc's __do_copy_data, and I'd have to use the ld instruction instead of ldi.
> In C++ you can abuse a reference to create an alias:
>
>
>
> static delay_t &tx_delay = *tx_delay_loc_inline;
>
>
>
> Or, perhaps, not abuse them at all:
>
>
>
> #if CONFIG_SUCH_AND_SUCH
>
> /* assuming Such and Such platform has a declared SUCH_AND_SUC_TX_DELAY
>
> as a global variable of type long */
>
> static long &tx_delay = SUCH_AND_SUCH_TX_DELAY;
>
> #endif
>
>
>
> I.e. C++ references at file scope de facto provide a similar capability to
>
> linker-level symbol aliasing (at least for objects, not functions).
I need it to be defined as a global symbol. My soft uart asm code gets compiled to a .o, and then linked with the main.o where the timing values (based on baud rate and CPU clock) are defined.
I tried:
const unsigned char &val = 42;
with g++, and val doesn't show up in the symbol table when I run nm.
Given everyone else's posts it looks like there's no way to do what I want in a completely portable way, so I'll stick with the few asm statements.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web