Like Tree2Likes

Problem!!!

This is a discussion on Problem!!! within the C Programming forums, part of the General Programming Boards category; Is it legal do declare this where you do? I'm mostly an embedded guy and this kind of dynamic declaration ...

  1. #16
    Registered User
    Join Date
    Mar 2011
    Posts
    261
    Is it legal do declare this where you do? I'm mostly an embedded guy and this kind of dynamic declaration is verboten. The compiler seems happy with it, but I dunno...

    Code:
    	int indexP1[size/2], indexP2[size/2];
    Also it's dilemma not dilema (misspellings like this can get you into trouble...)

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,618
    It is legal with respect to the 1999 edition of the C standard.
    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. #18
    Registered User
    Join Date
    Mar 2011
    Posts
    261
    Quote Originally Posted by laserlight View Post
    It is legal with respect to the 1999 edition of the C standard.
    OK, cool.

  4. #19
    Registered User
    Join Date
    Mar 2011
    Posts
    261
    Code:
    for(d=0; d<size-cols; d+cols)
    The third term should be something that changes 'd'. This doesn't causing the for loop to blow up.

    You still have no exit for no file found. May I suggest:
    Code:
    if(file == NULL) {
        printf("Sorry! The file could not be opened! Press a key to continue\n");
        getchar();
        return 1;
    }
    Last edited by mike65535; 04-20-2011 at 06:21 AM.

  5. #20
    Registered User
    Join Date
    May 2010
    Posts
    3,262
    I get the following warnings when I compile this code:
    main.c|13|warning: return type defaults to ‘int’|
    main.c||In function ‘main’:|
    main.c|54|warning: statement with no effect|
    ||=== Build finished: 0 errors, 2 warnings ===|
    You do have warnings enabled, right?

    And line 54 is:
    Code:
    for(d=0; d<size-cols; d+cols){
    Look closely at the last section of this statement (d+cols), this is a problem.

    Jim
    Salem likes this.

  6. #21
    Registered User
    Join Date
    Apr 2011
    Posts
    11
    Quote Originally Posted by mike65535 View Post
    Also it's dilemma not dilema (misspellings like this can get you into trouble...)
    Ha! I actually missed that until after I'd done several rewrites of the code and just left it that way because... laziness.

  7. #22
    Registered User
    Join Date
    Apr 2011
    Posts
    11
    Quote Originally Posted by jimblumberg View Post
    I get the following warnings when I compile this code:

    You do have warnings enabled, right?

    And line 54 is:
    Code:
    for(d=0; d<size-cols; d+cols){
    Look closely at the last section of this statement (d+cols), this is a problem.

    Jim
    I caught the "d+cols" mistake as soon as I took a look at that line alone (somehow that always helps). Also, how do you enable warnings? or check?

  8. #23
    Registered User
    Join Date
    May 2010
    Posts
    3,262
    Also, how do you enable warnings?
    This depends on how you are compiling. What compiler or IDE are you using, and what operating system?

    Jim

  9. #24
    Registered User
    Join Date
    Apr 2011
    Posts
    11
    I run ubuntu and I compile in the terminal using gcc.

  10. #25
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,618
    Then pass -Wall as an option when invoking the compiler. -pedantic and -std=c99 or -ansi may also come in handy.
    jimblumberg likes this.
    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

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  2. sturct/pointer problem, and fscanf problem
    By hiphop4reel in forum C Programming
    Replies: 6
    Last Post: 07-28-2008, 09:40 AM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 08:14 AM
  5. Texture Problem(I got the NeHe tut working, but I have a problem)
    By SyntaxBubble in forum Game Programming
    Replies: 2
    Last Post: 12-02-2001, 09:40 PM

Tags for this Thread


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