Question about comments


#1

I have come across something that I think Xcode doesn’t like. While reading the chapter on numbers and making my Numbers command line app I made comments inside of the code which I can refer to easily if I want to remember the summary on numbers the code is as follows:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, const char * argv[])
{
    /*-------------------------- INTEGERS
     char a; - 8 bit integer
     short b; - usually 16 bit integer  (depending on platform)
     int c; -usually 32 bit integer     (depending on platform)
     long d; - 32 or 64 bit             (depending on platform)
     long long e;  - 64 bit
     
     If you use an 'int' integer
     %d prints an integer as a decimal
     %o prints an integer in Octal
     %x prints an integer in Hexadecimal
     
     %f returns a floating number
     
     If you use 'long' - Must add an l in your token
     %ld - long decimal
     %lo - long octal
     %lx - long hexadecimal
     
     If using 'unsigned long'
     %lu - prints an unsigned long integer
     
     */
    printf(" 3 * 3 + 5 * 2 = %d\n", 3 * 3 + 5 * 2);
    printf("11 / 3.0 = %f\n", 11 / (float)3);
    /*
     Integer operations:
     + is addition
     - is subtraction
     / is integer devision, i.e. 11 / 3 = 3 (rounds to zero)
     % is modulo, returns the remainder, i.e. 11 % 3 = 2
    
    If you want to return a floating decimal must divide the denominator using a cast operator.
     
     printf("11 / 3.0 = %f\n", 11 / (float)3);  the (float) is the cast operator
     */
    
    
    printf("The remainder of 11 / 3 is %d\n", 11 % 3);
    printf("The absolute value of -5 is %d\n", abs(-5));
    
    /*
     Operator shorthand
     To increase a value by 1 we can use increment operator (++)
     int x = 5;
     x++; // now x is 6
     To decrease a value by 1 we can use a decrement operator (--)
     int x = 5;
     x--; // x is now 4
     
     If we want to increase x by more than one
     int = 5
     x += 6 x is now 11, 5 + 6
     Can read the previous line as "Assign x the value of x + 5"
     There is also -=, *=, /=, %=
     
     absolute value we have to use abs() and if the value is of a long we use labs()
     both of these functions are located in the stdlib.h
     */
    
    //--------------------Floating Numbers------------------------------\\
    /* floating numbers are decimals, can have various size:
     float g;           //32 Bit
     double h;          //64 Bit
     long double i;     //128 Bit
    **Floating numbers are always signed**
     
     Common tokens are:
     %f - returns a standard decimal
     %e - returns a scientific notation
     
     Adding a value before f or e limits how many decimal places we want.
     
     Must include math.h if I want to use the math library.  Trig, rounding, exponents, squares, cubes, ect...
     */
    
    double y = 12345.6789;
    printf("y is %f\n",y);
    printf("y is %e\n", y);

    return 0;
}

The problem I am encountering is Xcode won’t let me compile the code because it is reading my comments even though they have been clearly commented… It will only let me run the code if I put the ‘//’ on every line tat has some code. Is there something I’m missing or doing wrong? I have included a screen shot.

One more comment, its odd because it is only making the disruption in the Floating Numbers comments but not the Integer comments.


#2

In the line;
//--------------------Floating Numbers------------------------------\ <–delete the two trailing \'s and it will work - not sure why but it fixed the problem in Xcode 4.0.

Mitch


#3

Hi Mitch,

Thank you for the response! I just came on to explain that I found the thing causing the error which is the \ marks at the end. After playing around I found that these were causing issues. Now my question is why! I assume they have something to do with maybe ending some kind of comment or telling the compiler to skip some code or something. I’d love to hear a response if anyone knows.