Do I need to allow nested functions?

Discussion in 'Mac Programming' started by cybrscot, Jan 10, 2011.

  1. cybrscot, Jan 10, 2011
    Last edited: Jan 10, 2011

    cybrscot macrumors 6502

    cybrscot

    Joined:
    Dec 7, 2010
    Location:
    Somewhere in Southeast Asia
    #1
    ***Damn, update**** I figured it out. I needed to declare the int values separately. I don't know why I couldn't do it like I did below, but declaring them separately worked. Sorry!!!!!


    Hello! After taking the weekend off, due to work, sick, and needing to recharge the batteries after 4 straight chapters of learning to program, it's time to get going again. Anyway, my book asked me to show the output produced by each of the following code fragments, assume that i, j, and k are into variables.

    Did I do something wrong? Or do I need to enable nested functions? I've seen the nested functions error before, but it was because I made an error in my code, not because I needed to use nested functions.

    answer to below question is 63 8 By the way, I can do this in my head, but my compiler cannot!!

    Question 1:
    i = 7; j = 8;
    i *= j +1 ;
    printf ("%d %d", i, j) ;


    My code as follows, typed exactly as in the book....

    Code:
    #include <stdio.h>
    
    main ()
    {
    	int i = 7 ;
    	int j = 8 ;
    	int i *= j + 1 ;
    	
    	printf ("%d %d", i, j) ;
    	
    	return 0 ;
    	
    }	

    Output

    Users/scottdean/documents/fragment.c: In function ‘main’:
    /Users/scottdean/documents/fragment.c:7: error: nested functions are disabled, use -fnested-functions to re-enable
    /Users/scottdean/documents/fragment.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*=’ token
    /Users/scottdean/documents/fragment.c:7: error: expected expression before ‘*=’ token
     
  2. ChOas macrumors regular

    Joined:
    Nov 24, 2006
    Location:
    The Netherlands
    #2
    you are re-declaring i.

    Change the above to:

    Code:
    
    	int i = 7 ;
    	int j = 8 ;
    	i *= j + 1 ;
    	
    
     
  3. cybrscot thread starter macrumors 6502

    cybrscot

    Joined:
    Dec 7, 2010
    Location:
    Somewhere in Southeast Asia
    #3
    Thanks, oh I see, I declared the third line, which declared i again, makes sense now. Mind a bit rusty after two days off. This stuff keeps you sharp, well at least learning it from a book does!!
     

Share This Page