Thread: compilation issues

  1. #1
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305

    compilation issues

    Okay there is a strange thing happening with my Visual Studio. The thing is that when i compile the program it compiles fine but then later on i realised that there is a difference in the way the declaration of the functions is done and the way i am using the functions. So it should give me a compile error.

    PS: I copied the Visual Studio folder from my other computer to the laptop and started using it . So can this be an issue with this.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by roaan View Post
    Okay there is a strange thing happening with my Visual Studio. The thing is that when i compile the program it compiles fine but then later on i realised that there is a difference in the way the declaration of the functions is done and the way i am using the functions. So it should give me a compile error.

    PS: I copied the Visual Studio folder from my other computer to the laptop and started using it . So can this be an issue with this.
    Microsoft compilers are notoriously buggy. I'd recommend using gcc (cygwin or mingw), personally.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Sebastiani View Post
    Microsoft compilers are notoriously buggy. I'd recommend using gcc (cygwin or mingw), personally.
    Buggy? I haven't noticed any problems in the newer versions. VC++ 6.0 had some problems, but 2008 works great.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305
    What should i do to ensure that it works correctly?

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I'm not even sure what the problem is...
    Microsoft compilers are stable and generate good code, but can get confused and crash when doing heavy template code.
    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.

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by roaan View Post
    The thing is that when i compile the program it compiles fine but then later on i realised that there is a difference in the way the declaration of the functions is done and the way i am using the functions. So it should give me a compile error.
    Do you have an example?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Maybe there's something wrong with the dependencies in your build system. Try doing a full re-compile.

    Also, what kind of difference in the function signatures are you talking about? Some parameters might be automatically converted to the right type, and if you're using prototypes with empty parameter lists, then anything goes.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305
    This was one of the problems that i faced and it was pointed out here in the forum that the signatures of the functions that i was using is different and that it should not compile . But for me it was compiling as well as running.

    parent in a binary search tree

    Also just as a precaution i did the repair and reinstall feature of MSVS as well but to no avail.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I see what you mean.
    Code:
    struct node * inorder(struct node *root, struct node *temp);
    /* ... */
    struct node * inorder(struct node **root, struct node *temp)
    {
        /* ... */
    }
    All I can suggest then is making sure the file is saved, making sure you're compiling the right file (look at it in a different editor), and enabling warnings.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305
    i think i am facing another wrath from my compiler in the current program as well. I really dont understand what can be wrong with it. But its giving me 11 errors in a function that contains hardly 10 lines.

    [insert]
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define n 10
    
    int parseint(char *a);
    
    int main(int argc , char * argv[])
    {
    	int i, j;
    	//int n = parseint(argv[1]);
    	int a[n];
    	int k;
    	char *b = "123";
    
    	k = parseint(b);
    
    
    	printf("\n %d", RAND_MAX);
    	for(i = 0;i<n;i++)
    	{
    		int temp = rand()%10;
    		printf("\n%d", temp);
    		a[i] = temp;
    	}
    
    	for(i = 0; i<n ; i++){
    		for(j = 0; j<n-1 ;j++){
    			if(a[j] > a[j+1]){
    				int t = a[j];
    				a[j] = a[j+1];
    				a[j+1] = t;
    			}
    		}
    	}
    
    	printf("\n Array in ascending order");
    	for(i = 0; i< n;i++){
    		printf("\n %d", a[i]);
    	}
    	getch();
    	return 0;
    
    }
    
    int parseint(char *a)
    {
    	char *b;
    	int n;
    	int i = 0;
    	int sum = 0;
    	char c = *a;
    	b = a;
    	n = c - '0';
    	b++;
    	if(*b != '\0')
    	{
    		i++;
    		sum = sum*10 + n + parseint(*b);
    	}
    
    	if (i > 0)
    		return sum;
    	else
    		return n;
    }
    The list of errors is as follows:

    [insert]
    Code:
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(40) : warning C4013: 'getch' undefined; assuming extern returning int
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(48) : error C2143: syntax error : missing ';' before 'constant'
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(48) : warning C4091: ' ' : ignored on left of 'int' when no variable is declared
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(49) : error C2143: syntax error : missing ';' before 'type'
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(50) : error C2143: syntax error : missing ';' before 'type'
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(51) : error C2143: syntax error : missing ';' before 'type'
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(53) : error C2065: 'c' : undeclared identifier
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(53) : error C2106: '=' : left operand must be l-value
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(57) : error C2065: 'i' : undeclared identifier
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(58) : error C2065: 'sum' : undeclared identifier
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(58) : error C2065: 'sum' : undeclared identifier
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(58) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'char'
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(58) : warning C4024: 'parseint' : different types for formal and actual parameter 1
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(61) : error C2065: 'i' : undeclared identifier
    1>c:\documents and settings\rohan\my documents\visual studio 2008\projects\classc2\classc2\sort.c(62) : error C2065: 'sum' : undeclared identifier
    1>Build log was saved at "file://c:\Documents and Settings\ROHAN\My Documents\Visual Studio 2008\Projects\classc2\classc2\Debug\BuildLog.htm"
    1>classc2 - 11 error(s), 4 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Please suggest something what should i do... I seem to be going mad now

    Should i remove the application and try reinstalling it ? I like VS because i am pretty comfortable with it.

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    getch() is an ancient, unportable function which you shouldn't be using. See the FAQ.

    Should i remove the application and try reinstalling it ? I like VS because i am pretty comfortable with it.
    The third rule of programming: almost all of the time, it's you who is at fault and not the compiler. I'm not sure what the first and second rules are right at this moment, but if pressed I could make something up.

    Anyway, here's your problem.
    Code:
    #define n 10
    You do that, and then try to do
    Code:
    int n;
    The preprocessor happily turns this into
    Code:
    int 10;
    and the compiler throws its hands in the air and gives up.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's not Visual Studio that is in error; it's you.
    Problem: getch is undeclared. Cause: You haven't included the proper header. Solution: Obvious.
    Problem: Syntax error. Cause: You have a macro named n. Solution: Change macro or variable name.

    Also, you don't pay enough heed to warnings. Your previous code that you linked in this thread spewed out lots of warnings:
    Warning 6 warning C4047: 'function' : 'node **' differs in levels of indirection from 'node *' test.cpp 71
    Warning 7 warning C4024: 'searchparent' : different types for formal and actual parameter 1 test.cpp 71
    Warning 8 warning C4047: 'function' : 'node *' differs in levels of indirection from 'node **' test.cpp 121
    Warning 9 warning C4024: 'inorder' : different types for formal and actual parameter 1 test.cpp 121
    Warning 10 warning C4028: formal parameter 1 different from declaration test.cpp 127
    Warning 11 warning C4047: 'function' : 'node **' differs in levels of indirection from 'node *' test.cpp 131
    Warning 12 warning C4024: 'inorder' : different types for formal and actual parameter 1 test.cpp 131
    Warning 13 warning C4047: 'function' : 'node **' differs in levels of indirection from 'node *' test.cpp 147
    Warning 14 warning C4024: 'inorder' : different types for formal and actual parameter 1 test.cpp 147
    Warning 15 warning C4028: formal parameter 1 different from declaration test.cpp 152
    Warning 16 warning C4101: 'temp' : unreferenced local variable test.cpp 262
    Warning 17 warning C4715: 'inorder' : not all control paths return a value test.cpp 149
    Warning 18 warning C4715: 'searchparent' : not all control paths return a value test.cpp 174
    Warning 19 warning C4715: 'searchloc' : not all control paths return a value test.cpp 216
    Last edited by Elysia; 08-27-2009 at 01:45 PM.
    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.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Problem: getch is undeclared. Cause: You haven't included the proper header. Solution: Obvious.
    Umm, right. And which header file would one include for getch() in Visual Studio?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If you can't find it, remove it
    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.

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I'll have to remember that the next time I'm googling something. If you can't find what you're looking for, remove the web browser . . . ? Not sure how helpful that would be.

    For what it's worth: SourceForge.net: Pause console - cpwiki

    [edit] Also, I should mention that standard practice is to declare macros in all uppercase, for this very reason. If normal identifiers and macros both have the same naming conventions, it's hard to tell one from the other. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 07-03-2009, 11:20 AM
  2. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  3. MS VC++ Crash on compilation
    By Magos in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 08-23-2003, 07:06 PM
  4. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM
  5. Preproccessor conditional compilation
    By Garfield in forum C Programming
    Replies: 5
    Last Post: 09-28-2001, 09:28 AM