Thread: Warning Error

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    58

    Warning Error

    My program compiles and works correctly, but I have this warning:

    Warning W8027 workingArea2.cpp 76: Functions containing for are not expanded inline

    what does that error mean ?


    Code:
    #include <iostream>
    using namespace std;
    
    class CRectangle 
    {
          private:
      int x;
       string y;
    
    
      public:
        void set_values (int,string);
    
    	
    	
    	
    	 string check()
    	 {
    
    	  int flag = 0;
    	  
    		if (x!=4)
    			cout << "false"<<endl;
    		else
    			for(int i=0;i<x;i++)
    			{
    				if (y[i]=='4')
    				{
    					cout << "correct"<<endl;
    					flag = 1;
    				}
    			}
    			
    			if(flag == 0){
    			
    			cout<<"incorrect"<<endl;
    			}
    
    		return  y;
    	 }
    	 
    	 string check2()
    	 {
    	 	}
    };
    
    
    	
    void CRectangle::set_values (int a, string b) {
      x = a;
      y = b;
    }
    
    int main () {
      	
    	int length;
    	string codeNumber;
       string mystr = codeNumber;
    	
    	
    	cout << "Insert a code of 4 characters:";
    	cin >> codeNumber;
    	length = codeNumber.length();
      
       CRectangle rect;
       rect.set_values (length,codeNumber);
        rect.check();
       return 0;
    }
    Last edited by aama100; 02-03-2008 at 12:27 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    There is no line 76, so I have no idea what you are talking about.

    Also, please indent your code consistently.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    58
    oh my bad! it is line 26
    Warning W8027 workingArea2.cpp 26: Functions containing for are not expanded inline

    Code:
    		for(int i=0;i<x;i++)
    			{
    				if (y[i]=='4')
    				{
    					cout << "correct"<<endl;
    					flag = 1;
    				}
    			}

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Learn to split class definition and implementation.
    Also learn to indent properly.
    Click the link. Read. Absolutely no ignoring, okay? Very important information. Things that you need to know. That sort of stuff.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    It probably just means that it's that particular compiler's policy to never inline functions containing a for loop, therefore check() will not be inlined, even though you put its definition inside the class definition, which means you're requesting that it be inlined.

  6. #6
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Funny, but I'm compiling with -Wall -Wextra -Werror -pedantic and I don't get that error.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The warning message is pretty clear : if you have a for-loop in a function, the compiler can not inline the function. Member functions declared inside the class declaration will automatically be classed as "inline functions" - so the compiler tells you that "you asked [implicitly by putting it in the class declaration] that this function should be inlined, but I'm not doing it, because of the for-loop".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Pretty useless warning, that. What compiler is this? Borland or Intel?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    I don't know how bad it is to inline that particular function, the importance of that issue seems like nothing next to the rest of the issues going on here...

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Well, the compiler is not required to inline a function even when you tell it to, so that warning can be ignored.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    Pretty useless warning, that. What compiler is this? Borland or Intel?
    Using google, it appears that this warning is issued by some Borland compilers - and I agree, it's pretty useless warning - [and it's a pretty silly rule too - why can't a for-loop be inlined?]

    But the warnin gmessage itself isn't particularly cryptic. The ones that say "lvalue required" or "expected integer" are often harder to figure out for the novice. I think it's the implicit inline that is part of the original poster's difficulty to understand the message.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    it's a pretty silly rule too - why can't a for-loop be inlined?
    I think it is less a matter of "I cannot do it" and more "I decided not to do it".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    I think it is less a matter of "I cannot do it" and more "I decided not to do it".
    Sure, but it's still a "silly" decision - at least for modern systems.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    aama100 take a look at this:
    Code:
    #include <iostream>
    using namespace std;
    
    
    class CRectangle 
    {
    	public:
        
        	        void set_values(int, string);
    		string check();
    	 	string check2();
    	 	
    	private:
    	
    		int x;
    		string y;
    };
    
    
    void CRectangle::set_values (int a, string b)
    {
      	x = a;
      	y = b;
    }
    
    
    string CRectangle::check()
    {
    	int flag = 0;
    	  
    	if(x != 4)
    	{
    		cout << "false"<< endl;
    	}
    		
    	else
    	{
    		for(int i=0; i<x; i++)
    		{
    			if(y[i] == '4')
    			{
    				cout << "correct"<<endl;
    				flag = 1;
    			}
    		}
    			
    		if(flag == 0)
    		{
    			cout<<"incorrect"<<endl;
    		}
    	}
    
    	return  y;
    }
    
    
    int main () {
      	
    	int length;
    	string codeNumber;
       	string mystr = codeNumber;
    	
    	cout << "Insert a code of 4 characters:";
    	cin >> codeNumber;
    	length = codeNumber.length();
      
       	CRectangle rect;
       	rect.set_values (length,codeNumber);
            rect.check();
       
       	return 0;
    }
    Do you see the difference? Listen to what Elysia has told you, not only about indentation, but about leaning to use classes as well.

    Ask yourself: what am I doing here? -before you start hammering out code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM