public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Daniel Lohmann <daniel.lohmann@informatik.uni-erlangen.de>
To: Ron Kreymborg <ron@jennaron.com.au>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Mangle functions
Date: Thu, 31 Jan 2008 17:51:00 -0000	[thread overview]
Message-ID: <32D64922-63DC-4171-8D69-7064FAC158B1@informatik.uni-erlangen.de> (raw)
In-Reply-To: <000301c86303$3be6eae0$b3b4c0a0$@com.au>


On 30.01.2008, at 06:44, Ron Kreymborg wrote:

>>> The interrupt class does not need a this pointer as it neither calls
>>> other
>>> methods in its class or accesses any private class data, so the
>>> interrupt
>>> method itself can correctly be non-static.
>>
>> Well, "correctly" is a bit strong here. In fact, the behaviour is
>> undefined and it is just a case of luck (read: compiler-specifica)
>> that it works.  Whereas depending on compiler-specifica is acceptable
>> for programming on this level, it is just not necessary in your case.
>
> By "correctly" I meant it works fine this way, not that it was the  
> only way.
> Not sure what you mean about undefined. What is undefined?
>>
>> So why do you not just make it a class function (static) instead of a
>> member function? They can be private as well, friends as well, their
>> calling semantics is defined, and the *compiler* would make sure that
>> you do not (accidentally) access any member elements. No
>> disadvantages, but more safety.
>
> Good point. My interrupt classes never have local data, so the  
> possibility
> never came up. But for more general use I agree, "static" is the  
> safer way
> to go.

Undefined means that this situation is not specified by the standard.  
The compiler is free to assume that this points to a valid instance  
and to do what it wants with it.  So if you ever switch to another  
compiler or the gcc folks decide for whatever reason to do something  
fancy in methods, you are lost. This is not very likely, but  
nevertheless an avoidable risk. For principle reasons such risks  
should be avoided.

>
>> Moreover, class functions can be given "C" linkage. Andrew is right
>>

> Yes, this is almost working. In the avr-gcc case, a plethora of  
> processors
> have much the same peripherals and the compiler managers have rightly
> standardized on common names for common peripherals, with the  
> translation to
> the correct vector done via processor specific macros. My last  
> problem looks
> like it should be easy but I have run out of ideas. It is in the  
> method
> declaration. For example:
>
> static void MyOverflowInterrupt(void) asm(TIMER0_OVF_vect)
>                 __attribute__ ((signal, __INTR_ATTRS));
>
> Somewhere in the device header for a particular processor is the line:
>
> #define TIMER0_OVF_vect      _VECTOR(16)
>
> And elsewhere is defined:
>
> #define _VECTOR(N)  __vector_ ## N
>
> So the definition becomes the almost correct:
>
> static void MyOverflowInterrupt(void) asm(__vector_16)
>                 __attribute__ ((signal, __INTR_ATTRS));
>
> How do I get it to be:
>
> static void MyOverflowInterrupt(void) asm("__vector_16")
>                 __attribute__ ((signal, __INTR_ATTRS));

Oh, this one is actually easy :-)

You just need another macro-indirection that uses the "stringify"  
operator (#) of the pre-processor:

 >>>>
lohmann@mocca:~/tmp$ cat test.cpp
#define TIMER0_OVF_vect      _VECTOR(16)
#define _VECTOR(N)  __vector_ ## N

#define IRQ_VECTOR(vec) asm(#vec) __attribute__ ((signal, __INTR_ATTRS))

class Timer0 {
   static void MyOverflowInterrupt(void) IRQ_VECTOR(TIMER0_OVF_vect);
};
<<<<

After pre-processing this becomes:

 >>>>
lohmann@mocca:~/tmp$ g++ -E test.cpp

class Timer0 {
   static void MyOverflowInterrupt(void) asm("TIMER0_OVF_vect")  
__attribute__ ((signal, __INTR_ATTRS));
};
<<<<

Daniel

P.S. Answers to to the list, please. Other readers might  be  
interested and contribute as well.

  parent reply	other threads:[~2008-01-30  7:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-28 10:22 Ron Kreymborg
2008-01-28 17:22 ` Daniel Lohmann
2008-01-28 19:23   ` Andrew Haley
2008-01-28 19:25     ` Ron Kreymborg
2008-01-29  0:54       ` Daniel Lohmann
     [not found]         ` <000301c86303$3be6eae0$b3b4c0a0$@com.au>
2008-01-31 17:51           ` Daniel Lohmann [this message]
2008-01-28 18:12 ` Brian Dessent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=32D64922-63DC-4171-8D69-7064FAC158B1@informatik.uni-erlangen.de \
    --to=daniel.lohmann@informatik.uni-erlangen.de \
    --cc=gcc-help@gcc.gnu.org \
    --cc=ron@jennaron.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).