Warning Error

This is a discussion on Warning Error within the C++ Programming forums, part of the General Programming Boards category; My program compiles and works correctly, but I have this warning: Warning W8027 workingArea2.cpp 76: Functions containing for are not ...

  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 11:27 AM.

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

    Also, please indent your code consistently.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    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,893
    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
    21,647
    Well, the compiler is not required to inline a function even when you tell it to, so that warning can be ignored.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,647
    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".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 04: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, 04:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21