Statement has no effect PSTR - ?

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Guys,
I'd like to ask you for the problem you could came across. In my program I tried to use following:

1. strcasecmp_P( CmndPtr, PSTR( "string" )
2. strpbrk_P(Command, PSTR(":?"))

3.strtok_rP( Command, PSTR(":"), &Addr);

The 1st and 2nd line gave warning: "Statement has no effect 'PSTR("...") whilst the 3rd did NOT. What is strange, my private functions which use the flash mem do accept PSTR macro. Where is the problem? robiw

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you don't use the result of the comparison, the comparison can be thrown away.

strtok has side effects and cannot be optimized out alone from the fact that the return value us unused.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
In fact I use all of the function's results in "if" statements. So, the problem seems to be different. Robiw

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

In fact I use the result of this function in "if" statement.

This is not a quiz site. Don't play guessing games with us. Show smallest complete program that displays the problem you want to discuss.

(Don't forget to use CODE tags to avoid the forum software replacing bi- and -trigraphs with emoticons etc.)

The quality of the answers you get is highly correlated to the quality of your question.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok. You're right but it is not the matter to be so nervous. I'd like to simplyfy the problem. I'm in fact young user but not young programmer. So, be more flexible, please. Robiw

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am not nervous at all. I am simply stating that in order to get a good answer you need to supply full detail of the problem. E.g. instead of saying

Quote:
In fact I use all of the function's results in "if" statements.

why not simply be unambiguous and show some actual code?

It was you who asked

Quote:
Where is the problem?

and if you want a good and definite answer to that it is up to you to supply information enough.

Suppose I ask you this: "I turn the ignition key on my car but it won't start. Where is the problem?"

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
To be honest, it was a bit hard to post my question and attach code from my Nokia's browser ;-). Coming back to the problem, the code is:

if ( strpbrk_P(Command, PSTR(":?")))... //it makes a warning...

if ( strcasecmp_P( CmndPtr, PSTR("AT+ADC") ) == 0 )... //it makes a warning too...

CmndPtr = strtok_rP( Command, PSTR(":"), &Addr)  //This, for instance doesn't make a warning...

robiw

PS.
The warning: Statement has no effect PSTR... I can attach full code if it is needed...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Obviously it is not practical to post code from a Nokia. Simply say this in your first post: "I have this problem ... (I am not at my PC at the moment)"

However you can post a minimal compilable program from your PC when convenient. Then I guess you will get an answer very promptly.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, we will wait until you are at your AVR development machine where you have better opportunities to make extensive posts.

Again, the best you can do is to cut your code down to an absolute minimum that still displays the warnings, and then post that code here.

As an indicator of what I am talking about, I tried this minimal test:

#include 
#include 

// Some dummy command
char * Command = "Ho-Hum!";

int main(void)
{
   while(1)
   {
      if ( strpbrk_P(Command, PSTR(":?")))
      {
         // Just do something involving volatile so as not to get optimized out
         PORTB = 0xFF;
      }
   }
}

and this produces no warning when building.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are no warnings.

I allowed to transform your, well "text", to a piece of valid C code.

After fixing dozens of syntax errors, and compiling with

    avr-gcc -mmcu=atmega8 foo.c -fsyntax-only -std=c99 -pedantic -W -Wall -Wextra
No error, no warning.

Your problem in somewhere else, outside that snippet or in the ... that you added for extra obfuscation.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I can attach full code if it is needed...

Still not nervous, but somehow flabbergasted that you are still not convinced that posting some complete code will be the best way to get help. :roll:

What you should not do is to post your actual application code, not cut down to minimal. It is your job to isolate the problem as best you can, and then we will be interested in helping you. Don't show us several hundred lines of code. Show us something like a "twenty-liner" where you have isolated the problem.

(Chances are that you will discover the problem yourself when cutting your code down...)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Guys,
Now, I'm at my PC ;-). The simplified code which causes warnings as well:

#include 
#include 
#include 
#include 

volatile uint8_t ReceivedCommands;
char Command[10];

int main(void)
{
  char *CmndPtr;
  char *Addr;

  while(1)
  {

	if( ReceivedCommands )
	{
         if ( strpbrk_P(Command, PSTR(":?"))) //Warning: Statement has no effect 'PSTR(":?")'
	{
	  CmndPtr = strtok_rP( Command, PSTR(":"), &Addr);
        if ( strcasecmp_P( CmndPtr, PSTR("AT+ADC") ) == 0 ) PORTB = 0xFF;  //Warning: Statement has no effect 'PSTR("AT+ADC")'
		}
	}
}
}

What is more, and what might seem to be a bit stupid, I have the impression that the problems appeared since I reinstall Eclipse IDE - they started being highlighted ("yellow bugs") in the edit window. Best regards...robiw

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include 
extern void initstdio(void);

volatile uint8_t ReceivedCommands;
char Command[40];

int main(void)
{
	char *CmndPtr;
	char *Addr;
	initstdio();
	while(1)
	{
		printf_P(PSTR("Enter command :"));
		gets(Command);
		ReceivedCommands = 1;
		if( ReceivedCommands )
		{
			if ( strpbrk_P(Command, PSTR(":?"))) 
			{
				CmndPtr = strtok_rP( Command, PSTR(":"), &Addr);
				printf("cmdptr = \"% s\"\r\n", CmndPtr);
				if ( strcasecmp_P( CmndPtr, PSTR("AT+ADC") ) == 0 ) 
				    printf_P(PSTR("strcase found \r\n")); 
			}
			ReceivedCommands = 0;
		}
	}
}

Now, if you want to give some test strings, you can say what result you want.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

robiw wrote:
simplified code which causes warnings as well

I just did a test build of your code. No warnings here...

Give us the following information:
- What AVR model are you building for?
- What version of avr-gcc are you using?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
the problems appeared since I reinstall Eclipse IDE - they started being highlighted ("yellow bugs") in the edit window.
So is it actually a warning coming from the compiler, or merely a warning of the IDE?

I bet it is the latter, because the gcc warning I know is "statement with no effect" (note the "with" instead of "has") and it does not come with a quote of the statement.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Colleagues,
I attached image from my PC. As you can see Console tab has no problems whilst Error tab has one error and two warnings. I think, it can come from IDE Eclipse, not from compiler but why? The last time I use the IDE (before reinstalling to the same) there were no problems. robiw

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

robiw wrote:
I think, it can come from IDE Eclipse, not from compiler but why?
If you look at the PSTR macro you will see that it ends with "&__c[0];})". Someone, who don't know that a GCC extension is used here to "return" something from a code block, could think that it is a statement with no effect. Why Eclipse doesn't show the warning for all instances of PSTR then? Who knows.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sternst wrote:
Someone, who don't know that a GCC extension is used here to "return" something from a code block, could think that it is a statement with no effect.

But the "return" is used withing all these str functions, so? robiw

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

robiw wrote:
But the "return" is used withing all these str functions, so?
But the "return" itself is a statement with no effect. It is like this (assigning 3 to var):

var = ({uint8_t x = 1; x+2;});

Within standard C a "x+2;" is a statement with no effect.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, I can't catch it. So, is there a real problem or only the theoretical one? robiw

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
So, is there a real problem or only the theoretical one?

The message you are seeing is coming from the module in Eclipse that evaluates code while you type. It is not the compiler emitting these messages but a different piece of software.

The final say on if there is a problem or not should be left to the compiler.

Since you say that you have re-installed Eclipse and then started getting these messages then obviously something has changed as compared to your previous installation. Go back to your notes on what version you had installed, and what you have installed now and compare. This might give a hint.

And since this has nothing to do with the avr-gcc compiler, and probably everything to do with the C language module in Eclipse, then this ought to be a generic problem for any C development in Eclipse, not only AVRs. So... I just tested a very quick Google for "statement has no effect Eclipse GCC" and I get many hits. I suggest you do that Googling, and study the results. I see indications that adding a pair of parenthesis might make the bogus warning go away.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

robiw wrote:
So, is there a real problem or only the theoretical one?
No problem at all (apart from a false warning made by Eclipse).

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you look at the macro expanded code everything will be clear :-). Or not :-(

 if( ReceivedCommands )
 {
     if ( strpbrk_P(Command, (__extension__({static char __c[] __attribute__((__progmem__)) = (":?"); &__c[0];}))))
     {
  CmndPtr = strtok_rP( Command, (__extension__({static char __c[] __attribute__((__progmem__)) = (":"); &__c[0];})), &Addr);
  if ( strcasecmp_P( CmndPtr, (__extension__({static char __c[] __attribute__((__progmem__)) = ("AT+ADC"); &__c[0];})) ) == 0 ) (*(volatile uint8_t *)((0x18) + 0x20)) = 0xFF;
     }
 }
    }

:wink:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Colleagues,
Thanks a lot for the answers! In fact, I have been programmed AVR micro since few years but with basic (I know, it was mistake ;-)) and had to change many of my habits ;-). The Eclipse's re-installation was not in fact re-installation because Eclipse doesn't need to be installed, only unpacked :-). So, I don't know where the problem comes from. Nevermind. I just change my Juno to Indigo Eclipse. The expanded macro code above doesn't make me fell the problem :-(...best regards...robiw