EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

expression has not efect

Started by "Daniel H. Sagarra" April 28, 2007
Some one know why the compiler warring at: set_bit (i,3);
in the folowing code ?:

#define bit_set(a,b) ((a) | (1 << (b)))

main()
{
static int i = 1;
bit_set (i,3); // expression has no efect
i |= (1<<3);
i++;
while(1);
}

Beginning Microcontrollers with the MSP430

what's the warning?

could it be something about the previous line that doesn't assign a value to
anything?

Rachel Adamec
Norristown, PA USA

-----Original Message-----
From: m... [mailto:m...] On Behalf Of
Daniel H. Sagarra
Sent: Saturday, April 28, 2007 2:20 PM
To: m...
Subject: [msp430] expression has not efect

Some one know why the compiler warring at: set_bit (i,3);
in the folowing code ?:

#define bit_set(a,b) ((a) | (1 << (b)))

main()
{
static int i = 1;
bit_set (i,3); // expression has no efect
i |= (1<<3);
i++;
while(1);
}
Warning[Pe174]: expression has no effect C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c 8

.lst:

C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c
1 #include
2
3 #define bit_set(a,b) ((a) | (1 << (b)))
4

\ In segment CODE, align 2
5 main()
\ main:
6 {
7 static int i = 1;
8 bit_set (i,3);
\ 000000 1F42.... MOV.W &??i, R15
\ 000004 3FD2 BIS.W #0x8, R15
9 i |= (1<<3);
\ 000006 B2D2.... BIS.W #0x8, &??i
10 i++;
\ 00000A 9253.... ADD.W #0x1, &??i
11 while(1);
\ ??main_0:
\ 00000E FF3F JMP ??main_0
12 }

\ In segment DATA16_I, align 2, align-sorted
\ 000000 REQUIRE ?cstart_init_copy
\ ??i:
\ 000000 DS8 2
\ 000002 REQUIRE `?`

\ In segment DATA16_ID, align 2, align-sorted
\ `?`:
\ 000000 0100 DC16 1
----- Original Message -----
From: Rachel Adamec
To: m...
Sent: Saturday, April 28, 2007 3:38 PM
Subject: RE: [msp430] expression has not efect
what's the warning?

could it be something about the previous line that doesn't assign a value to
anything?

Rachel Adamec
Norristown, PA USA
-----Original Message-----
From: m... [mailto:m...] On Behalf Of
Daniel H. Sagarra
Sent: Saturday, April 28, 2007 2:20 PM
To: m...
Subject: [msp430] expression has not efect

Some one know why the compiler warring at: set_bit (i,3);
in the folowing code ?:

#define bit_set(a,b) ((a) | (1 << (b)))

main()
{
static int i = 1;
bit_set (i,3); // expression has no efect
i |= (1<<3);
i++;
while(1);
}





------
E-mail clasificado por el Idenfificador de Spam Inteligente. Para modificar la categor clasificada acceda a su webmail
------
Este mensaje ha sido verificado por el E-mail Protegido. Antivirus Actualizado en 27/04/2007 / Versi: 5.1.00/5019
Well, what it means is the expression has no effect.... what expression?
well the one on line 8 of bit-lib.c....

line 8 is:

8 bit_set (i,3);

This line is expanded to:

((i) | (1 << (3)))

OK, it shifts the "1" 3 bits to the left and or's that with i, which is
1... so this expression evaluates to '9'... but this isn't assigned to
anything, no variable is changed, nothing happens with it... so the compiler
is letting you know - whatever this evaluates to doesn't matter, because
this line has no effect on anything...

it's a warning - hey maybe you want this to do nothing... but if any
optimization is on, this statement should be ignored. It's not, it's
actually compiled:

\ 000000 1F42.... MOV.W &??i, R15
\ 000004 3FD2 BIS.W #0x8, R15

(what's in 'i' is moved to register 15. the 1, shifted 3 bits, predetermined
to be "8", is then or'ed in using the "bit set" instruction)

But R15 is otherwise ignored.

Assign it to a variable that you use later and you will not get this
warning.

Rachel Adamec
Norristown, PA, USA

-----Original Message-----
From: m... [mailto:m...] On Behalf Of
Daniel H. Sagarra
Sent: Saturday, April 28, 2007 2:36 PM
To: m...
Subject: Re: [msp430] expression has not efect
Warning[Pe174]: expression has no effect
C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c 8
.lst:

C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c
1 #include
2
3 #define bit_set(a,b) ((a) | (1 << (b)))
4

\ In segment CODE, align 2
5 main()
\ main:
6 {
7 static int i = 1;
8 bit_set (i,3);
\ 000000 1F42.... MOV.W &??i, R15
\ 000004 3FD2 BIS.W #0x8, R15
9 i |= (1<<3);
\ 000006 B2D2.... BIS.W #0x8, &??i
10 i++;
\ 00000A 9253.... ADD.W #0x1, &??i
11 while(1);
\ ??main_0:
\ 00000E FF3F JMP ??main_0
12 }

0847/stime77785953/nc1E07179/nc2848643/nc3=3>
:) sorry I show use this define

#define bit_clear(a,b) ((a) &= ~(1 << (b)))
#define bit_set(a,b) ((a) |= (1 << (b)))

----- Original Message -----
From: Rachel Adamec
To: m...
Sent: Saturday, April 28, 2007 4:09 PM
Subject: RE: [msp430] expression has not efect
Well, what it means is the expression has no effect.... what expression?
well the one on line 8 of bit-lib.c....

line 8 is:

8 bit_set (i,3);

This line is expanded to:

((i) | (1 << (3)))

OK, it shifts the "1" 3 bits to the left and or's that with i, which is
1... so this expression evaluates to '9'... but this isn't assigned to
anything, no variable is changed, nothing happens with it... so the compiler
is letting you know - whatever this evaluates to doesn't matter, because
this line has no effect on anything...

it's a warning - hey maybe you want this to do nothing... but if any
optimization is on, this statement should be ignored. It's not, it's
actually compiled:

\ 000000 1F42.... MOV.W &??i, R15
\ 000004 3FD2 BIS.W #0x8, R15

(what's in 'i' is moved to register 15. the 1, shifted 3 bits, predetermined
to be "8", is then or'ed in using the "bit set" instruction)
But R15 is otherwise ignored.

Assign it to a variable that you use later and you will not get this
warning.

Rachel Adamec
Norristown, PA, USA
-----Original Message-----
From: m... [mailto:m...] On Behalf Of
Daniel H. Sagarra
Sent: Saturday, April 28, 2007 2:36 PM
To: m...
Subject: Re: [msp430] expression has not efect

Warning[Pe174]: expression has no effect
C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c 8

.lst:

C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c
1 #include
2
3 #define bit_set(a,b) ((a) | (1 << (b)))
4

\ In segment CODE, align 2
5 main()
\ main:
6 {
7 static int i = 1;
8 bit_set (i,3);
\ 000000 1F42.... MOV.W &??i, R15
\ 000004 3FD2 BIS.W #0x8, R15
9 i |= (1<<3);
\ 000006 B2D2.... BIS.W #0x8, &??i
10 i++;
\ 00000A 9253.... ADD.W #0x1, &??i
11 while(1);
\ ??main_0:
\ 00000E FF3F JMP ??main_0
12 }

0847/stime77785953/nc1E07179/nc2848643/nc3=3>



------
E-mail clasificado por el Idenfificador de Spam Inteligente. Para modificar la categor clasificada acceda a su webmail
------
Este mensaje ha sido verificado por el E-mail Protegido. Antivirus Actualizado en 27/04/2007 / Versi: 5.1.00/5019
Dear Reachel

I wrote a short source code to despite the problem,
even doing something else with the var i, after i = bit_set(3,i),
the warring persist,, I post the code with "a equivalent statment"
without using the macro, this statment dont trigger any warring,
all optimizacion are off (best debugging code),
for some else who don't read my first code, here is it again:

#define bit_set(a,b) ((a) | (1 << (b)))

main()
{
static int i = 1;
bit_set (i,3); // this statment trigger a warring: expression has no efect
i |= (1<<3); // this not trigger anything
i++;
while(1);
}

Best regards
Daniel H. Sagaar

----- Original Message -----
From: Rachel Adamec
To: m...
Sent: Saturday, April 28, 2007 4:09 PM
Subject: RE: [msp430] expression has not efect
Well, what it means is the expression has no effect.... what expression?
well the one on line 8 of bit-lib.c....

line 8 is:

8 bit_set (i,3);

This line is expanded to:

((i) | (1 << (3)))

OK, it shifts the "1" 3 bits to the left and or's that with i, which is
1... so this expression evaluates to '9'... but this isn't assigned to
anything, no variable is changed, nothing happens with it... so the compiler
is letting you know - whatever this evaluates to doesn't matter, because
this line has no effect on anything...

it's a warning - hey maybe you want this to do nothing... but if any
optimization is on, this statement should be ignored. It's not, it's
actually compiled:

\ 000000 1F42.... MOV.W &??i, R15
\ 000004 3FD2 BIS.W #0x8, R15

(what's in 'i' is moved to register 15. the 1, shifted 3 bits, predetermined
to be "8", is then or'ed in using the "bit set" instruction)
But R15 is otherwise ignored.

Assign it to a variable that you use later and you will not get this
warning.

Rachel Adamec
Norristown, PA, USA
-----Original Message-----
From: m... [mailto:m...] On Behalf Of
Daniel H. Sagarra
Sent: Saturday, April 28, 2007 2:36 PM
To: m...
Subject: Re: [msp430] expression has not efect

Warning[Pe174]: expression has no effect
C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c 8

.lst:

C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c
1 #include
2
3 #define bit_set(a,b) ((a) | (1 << (b)))
4

\ In segment CODE, align 2
5 main()
\ main:
6 {
7 static int i = 1;
8 bit_set (i,3);
\ 000000 1F42.... MOV.W &??i, R15
\ 000004 3FD2 BIS.W #0x8, R15
9 i |= (1<<3);
\ 000006 B2D2.... BIS.W #0x8, &??i
10 i++;
\ 00000A 9253.... ADD.W #0x1, &??i
11 while(1);
\ ??main_0:
\ 00000E FF3F JMP ??main_0
12 }

0847/stime77785953/nc1E07179/nc2848643/nc3=3>



------
E-mail clasificado por el Idenfificador de Spam Inteligente. Para modificar la categor clasificada acceda a su webmail
------
Este mensaje ha sido verificado por el E-mail Protegido. Antivirus Actualizado en 27/04/2007 / Versi: 5.1.00/5019
Have you tried saying that i = set_bit(a, b)?

To me, it having "No effect" means that the expression is evaluated,
however, nothing is done with the result.

On 4/28/07, Daniel H. Sagarra wrote:
>
> Warning[Pe174]: expression has no effect
> C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c 8
> .lst:
>
> C:\Proyectos\IAR\msp430\bit_lib\bit_lib.c
> 1 #include
> 2
> 3 #define bit_set(a,b) ((a) | (1 << (b)))
> 4
>
> \ In segment CODE, align 2
> 5 main()
> \ main:
> 6 {
> 7 static int i = 1;
> 8 bit_set (i,3);
> \ 000000 1F42.... MOV.W &??i, R15
> \ 000004 3FD2 BIS.W #0x8, R15
> 9 i |= (1<<3);
> \ 000006 B2D2.... BIS.W #0x8, &??i
> 10 i++;
> \ 00000A 9253.... ADD.W #0x1, &??i
> 11 while(1);
> \ ??main_0:
> \ 00000E FF3F JMP ??main_0
> 12 }
>
> \ In segment DATA16_I, align 2, align-sorted
> \ 000000 REQUIRE ?cstart_init_copy
> \ ??i:
> \ 000000 DS8 2
> \ 000002 REQUIRE `?`
>
> \ In segment DATA16_ID, align 2, align-sorted
> \ `?`:
> \ 000000 0100 DC16 1
>
> ----- Original Message -----
> From: Rachel Adamec
> To: m...
> Sent: Saturday, April 28, 2007 3:38 PM
> Subject: RE: [msp430] expression has not efect
>
> what's the warning?
>
> could it be something about the previous line that doesn't assign a value
> to
> anything?
>
> Rachel Adamec
> Norristown, PA USA
>
> -----Original Message-----
> From: m... [mailto:
> m... ] On Behalf Of
> Daniel H. Sagarra
> Sent: Saturday, April 28, 2007 2:20 PM
> To: m...
> Subject: [msp430] expression has not efect
>
> Some one know why the compiler warring at: set_bit (i,3);
> in the folowing code ?:
>
> #define bit_set(a,b) ((a) | (1 << (b)))
>
> main()
> {
> static int i = 1;
> bit_set (i,3); // expression has no efect
> i |= (1<<3);
> i++;
> while(1);
> }
>
>
>
>
>
> ----------------------
> E-mail clasificado por el Idenfificador de Spam Inteligente. Para
> modificar la categor clasificada acceda a su webmail
>
> ----------------------
> Este mensaje ha sido verificado por el E-mail Protegido. Antivirus
> Actualizado en 27/04/2007 / Versi: 5.1.00/5019
>
>
>
>
>
HI Daniel,

I may be getting tripped up by what you wrote, but I think you're saying
that, with this code, the error persists... even if you change the line to
"i=bit_set(i,3);" If I'm not clear or not understanding what you're saying,
I'm sorry.

What you included was:

> main()
> {
> static int i = 1;
> bit_set (i,3); // this statment trigger a warring: expression has no efect
> i |= (1<<3); // this not trigger anything
> i++;
> while(1);
> }

Again, the result of your bit_set operation is not used, not assigned to a
variable, not saved. I wonder if you think your statement is supposed to set
the "b" bit of the "a" variable. If so, you have an error in your "define"

> #define bit_set(a,b) ((a) | (1 << (b)))

Maybe you want it to read:

#define bit_set(a,b) ((a) |= (1 << (b)))

(note the '=' included in the define)?

Or your code could read:

i = bit_set (i,3);

Hope this helps.

Rachel Adamec
Norristown, PA, USA

-----Original Message-----
From: m... [mailto:m...] On Behalf Of
Daniel H. Sagarra
Subject: Re: [msp430] expression has not efect

Dear Reachel

I wrote a short source code to despite the problem,
even doing something else with the var i, after i = bit_set(3,i),
the warring persist,, I post the code with "a equivalent statment"
without using the macro, this statment dont trigger any warring,
all optimizacion are off (best debugging code),
for some else who don't read my first code, here is it again:

#define bit_set(a,b) ((a) | (1 << (b)))

main()
{
static int i = 1;
bit_set (i,3); // this statment trigger a warring: expression has no efect
i |= (1<<3); // this not trigger anything
i++;
while(1);
}

.

0851/stime77790369/nc1E07179/nc2848641/nc3=3>
You are right .
sorry I shold use this define

#define bit_clear(a,b) ((a) &= ~(1 << (b)))
#define bit_set(a,b) ((a) |= (1 << (b)))
Best regards
Daniel H. Sagarra
Buenos Airesm Argentina

----- Original Message -----
From: Rachel Adamec
To: m...
Sent: Sunday, April 29, 2007 8:15 AM
Subject: RE: [msp430] expression has not efect
HI Daniel,

I may be getting tripped up by what you wrote, but I think you're saying
that, with this code, the error persists... even if you change the line to
"i=bit_set(i,3);" If I'm not clear or not understanding what you're saying,
I'm sorry.

What you included was:

> main()
> {
> static int i = 1;
> bit_set (i,3); // this statment trigger a warring: expression has no efect
> i |= (1<<3); // this not trigger anything
> i++;
> while(1);
> }

Again, the result of your bit_set operation is not used, not assigned to a
variable, not saved. I wonder if you think your statement is supposed to set
the "b" bit of the "a" variable. If so, you have an error in your "define"

> #define bit_set(a,b) ((a) | (1 << (b)))

Maybe you want it to read:

#define bit_set(a,b) ((a) |= (1 << (b)))

(note the '=' included in the define)?

Or your code could read:

i = bit_set (i,3);

Hope this helps.

Rachel Adamec
Norristown, PA, USA
-----Original Message-----
From: m... [mailto:m...] On Behalf Of
Daniel H. Sagarra
Subject: Re: [msp430] expression has not efect

Dear Reachel

I wrote a short source code to despite the problem,
even doing something else with the var i, after i = bit_set(3,i),
the warring persist,, I post the code with "a equivalent statment"
without using the macro, this statment dont trigger any warring,
all optimizacion are off (best debugging code),
for some else who don't read my first code, here is it again:

#define bit_set(a,b) ((a) | (1 << (b)))

main()
{
static int i = 1;
bit_set (i,3); // this statment trigger a warring: expression has no efect
i |= (1<<3); // this not trigger anything
i++;
while(1);
}

.

0851/stime77790369/nc1E07179/nc2848641/nc3=3>


------
E-mail clasificado por el Idenfificador de Spam Inteligente. Para modificar la categor clasificada acceda a su webmail
------
Este mensaje ha sido verificado por el E-mail Protegido. Antivirus Actualizado en 27/04/2007 / Versi: 5.1.00/5019
The problem is in the macro definition.
You need to remove the parenthesis from the 'a' variable.
Since it is in parenthesis, it gets turned into a value, not a variable.

For instance ...

int x = 0;

(x) |= 9; // this doesn't assign anything to x

Change your macro to ...

#define bit_set(a,b) a |= (1 << (b))

See if that makes any difference.

--- In m..., "Daniel H. Sagarra"
wrote:
>
> You are right .
> sorry I shold use this define
>
> #define bit_clear(a,b) ((a) &= ~(1 << (b)))
> #define bit_set(a,b) ((a) |= (1 << (b)))
> Best regards
> Daniel H. Sagarra
> Buenos Airesm Argentina

The 2024 Embedded Online Conference