Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #11799

Re: Multi-instructions macro and compiler warning

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Multi-instructions macro and compiler warning
Date 2011-10-17 23:04 +1300
Message-ID <9g2cslF3u9U8@mid.individual.net> (permalink)
References (2 earlier) <j7e1qm$7te$1@nnrp.ngi.it> <9fvgkdF3u9U3@mid.individual.net> <j7e3tk$9v2$1@nnrp.ngi.it> <9fvoqnF3u9U5@mid.individual.net> <bc5ef864-1b35-4ea4-a57f-d3a2529493fa@f11g2000vbm.googlegroups.com>

Show all headers | View raw


On 10/17/11 10:37 PM, pozz wrote:
> On 16 Ott, 12:09, Ian Collins<ian-n...@hotmail.com>  wrote:
>> On 10/16/11 09:16 PM, pozz wrote:
>>> I tried, the linker I'm using can't.  Also the compiler (even with
>>> optimization) doesn't transform normal functions to inline functions,
>>> without the inline keyword.
>>
>> So use it!  At least the compiler honours the hint.  Embedded compilers
>> tend to offer more control over what is and isn't inlined than their
>> hosted brethren.
>
> Unfortunately, I have another "warning" problem if I use inline
> functions.
>
> Suppose I have a macro that activate a relay connected to a
> microcontroller pin:
>
>    #define RELAY_ON()  do {PIN_SET_OUTPUT(10); PIN_SET(PIN(10));}
> while(0)
>
> The first instruction is to configure the pin as an output; the second
> is to set its level to high.
>
> Transforming this macro to an inline function, I would write:
>
>    #pragma inline relay_on
>    void relay_on(void) {
>      PIN_SET_OUTPUT(10);
>      PIN_SET(PIN(10));
>    }
>
> If this function is accessible just from one compilation module, it is
> simple to use it:
>
> -- test.c --
> #include "cpu.h"
>
> #pragma inline relay_on
> static void relay_on(void) {
>    PIN_SET_OUTPUT(10);
>    PIN_SET(PIN(10));
> }
>
> void test(void) {
>    relay_on();
>    /* other things */
> }
> -- test.h --
> #ifndef TEST_H
> #define TEST_H
> #include "test.h"
> void test(void);
> #endif
> --
>
> The compilation ends without any errors and warnings.
>
> The problem happens when I try to use this function in more than one
> module,
> so moving the code to include file (I think this is the way to have an
> extern
> inline function):
>
> -- test.h --
> #ifndef TEST_H
> #define TEST_H
>
> #pragma inline relay_on
> void relay_on(void) {
>    PIN_SET_OUTPUT(10);
>    PIN_SET(PIN(10));
> }
>
> #endif
> --
>
> If I include test.h in more than one file, the compilation ends with
> the warning
>
>    W1327L: Duplicate symbol definition (_relay_on)
>
> even if the function relay_on() is never used. So the use of inline
> function to
> avoid a warning has produced another warning :-(
>
Well your "#pragma inline" doesn't follow the rules for inline 
functions.  if the compiler did,

inline void relay_on(void) {}

would avoid multiple inclusion.

Try "static void " rather than "inline void", it should have the same 
effect.

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Multi-instructions macro and compiler warning pozz <pozzugno@gmail.com> - 2011-10-16 09:09 +0200
  Re: Multi-instructions macro and compiler warning Ian Collins <ian-news@hotmail.com> - 2011-10-16 20:31 +1300
    Re: Multi-instructions macro and compiler warning pozz <pozzugno@gmail.com> - 2011-10-16 09:41 +0200
      Re: Multi-instructions macro and compiler warning Ian Collins <ian-news@hotmail.com> - 2011-10-16 20:49 +1300
        Re: Multi-instructions macro and compiler warning pozz <pozzugno@gmail.com> - 2011-10-16 10:16 +0200
          Re: Multi-instructions macro and compiler warning Ian Collins <ian-news@hotmail.com> - 2011-10-16 23:09 +1300
            Re: Multi-instructions macro and compiler warning pozz <pozzugno@gmail.com> - 2011-10-17 02:37 -0700
              Re: Multi-instructions macro and compiler warning Ian Collins <ian-news@hotmail.com> - 2011-10-17 23:04 +1300
              Re: Multi-instructions macro and compiler warning Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-17 11:06 +0100
                Re: Multi-instructions macro and compiler warning pozz <pozzugno@gmail.com> - 2011-10-17 03:23 -0700
              Re: Multi-instructions macro and compiler warning Keith Thompson <kst-u@mib.org> - 2011-10-17 12:30 -0700
      Re: Multi-instructions macro and compiler warning "BartC" <bc@freeuk.com> - 2011-10-16 12:47 +0100
        Re: Multi-instructions macro and compiler warning Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-10-16 22:16 +0000
        Re: Multi-instructions macro and compiler warning pozz <pozzugno@gmail.com> - 2011-10-17 02:42 -0700
          Re: Multi-instructions macro and compiler warning "BartC" <bc@freeuk.com> - 2011-10-17 13:10 +0100
      Re: Multi-instructions macro and compiler warning bert <bert.hutchings@btinternet.com> - 2011-10-16 05:33 -0700
  Re: Multi-instructions macro and compiler warning Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-16 09:02 -0400
  Re: Multi-instructions macro and compiler warning "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2011-10-16 07:40 -0700
    Re: Multi-instructions macro and compiler warning ImpalerCore <jadill33@gmail.com> - 2011-10-17 08:07 -0700
      Re: Multi-instructions macro and compiler warning "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2011-10-17 09:25 -0700
        Re: Multi-instructions macro and compiler warning James Kuyper <jameskuyper@verizon.net> - 2011-10-17 12:58 -0400
          Re: Multi-instructions macro and compiler warning Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-18 07:43 -0400
            Re: Multi-instructions macro and compiler warning Keith Thompson <kst-u@mib.org> - 2011-10-18 11:52 -0700
        Re: Multi-instructions macro and compiler warning ImpalerCore <jadill33@gmail.com> - 2011-10-17 10:41 -0700
  Re: Multi-instructions macro and compiler warning Jean-Christophe <5.d@free.fr> - 2011-10-16 10:02 -0700
    Re: Multi-instructions macro and compiler warning Kleuskes & Moos <kleuske@somewhere.else.net> - 2011-10-16 17:44 +0000
    Re: Multi-instructions macro and compiler warning Keith Thompson <kst-u@mib.org> - 2011-10-16 13:49 -0700
      Re: Multi-instructions macro and compiler warning Ian Collins <ian-news@hotmail.com> - 2011-10-17 10:00 +1300
  Re: Multi-instructions macro and compiler warning Kenneth Brody <kenbrody@spamcop.net> - 2011-10-17 12:50 -0400
    Re: Multi-instructions macro and compiler warning "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-10-17 14:50 -0400

csiph-web