Thread: Segmentation fault error

  1. #16
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by dwks View Post
    preprocessor directives have to begin with a '#' that is the first non-alphanumeric character on the line
    Not true.
    Code:
    C:\>type t.c
      #include <stdio.h>
    
    int main()
    {
            return 0;
    }
    
    C:\>gcc -ansi -pedantic -Wall t.c
    
    C:\>

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, indeed, I meant to say, "the first non-whitespace character on the line". Oops.

    BTW -- consider -W as well. It enables some other useful warnings I believe.

    (Italic hashes look very strange in this font, whatever it is. They appear to have only one semi-vertical line. Well, it's actually two fused directly together, because it looks a bit thick. It's just strange. )
    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.

  3. #18
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    -W didn't do anything more with the example program, but thanks for the tip.

    >Italic hashes look very strange in this font, whatever it is.

    Congratulations DWK, you speak Chinese!

  4. #19
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    -W didn't do anything more with the example program, but thanks for the tip.
    No, I wasn't really expecting it to. I just meant in general:
    -W
    Print extra warning messages for these events:

    * A function can return either with or without a value. (Falling off the end of the function body is considered returning without a value.) For example, this function would evoke such a warning:

    Code:
                             foo (a)
                             {
                               if (a > 0)
                                 return a;
                             }

    * An expression-statement or the left-hand side of a comma expression contains no side effects. To suppress the warning, cast the unused expression to void. For example, an expression such as x[i,j] will cause a warning, but x[(void)i,j] will not.
    * An unsigned value is compared against zero with < or <=.
    * A comparison like x<=y<=z appears; this is equivalent to (x<=y ? 1 : 0) <= z, which is a different interpretation from that of ordinary mathematical notation.
    * Storage-class specifiers like static are not the first things in a declaration. According to the C Standard, this usage is obsolescent.
    * The return type of a function has a type qualifier such as const. Such a type qualifier has no effect, since the value returned by a function is not an lvalue. (But don't warn about the GNU extension of volatile void return types. That extension will be warned about if -pedantic is specified.)
    * If -Wall or -Wunused is also specified, warn about unused arguments.
    * A comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned. (But don't warn if -Wno-sign-compare is also specified.)
    * An aggregate has a partly bracketed initializer. For example, the following code would evoke such a warning, because braces are missing around the initializer for x.h:

    Code:
                             struct s { int f, g; };
                             struct t { struct s h; int i; };
                             struct t x = { 1, 2, 3 };

    * An aggregate has an initializer which does not initialize all members. For example, the following code would cause such a warning, because x.h would be implicitly initialized to zero:

    Code:
                             struct s { int f, g, h; };
                             struct s x = { 3, 4 };
    From http://gcc.gnu.org/onlinedocs/gcc-3....&#37;20Options

    >Italic hashes look very strange in this font, whatever it is.

    Congratulations DWK, you speak Chinese!
    Er -- what? How are strange italic hashes Chinese? Actually, come to think of it . . .
    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.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I do not recall there being a Chinese word that is pictorially equivalent to a #.

    But yeah, I always assumed -W was some subset of -Wall. The "all" apparently is rather misleading.
    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

  6. #21
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Quote Originally Posted by laserlight View Post
    I do not recall there being a Chinese word that is pictorially equivalent to a #.

    But yeah, I always assumed -W was some subset of -Wall. The "all" apparently is rather misleading.
    The following is a snippet from the GCC man page (-W being the same as -Wextra):
    -Wall
    All of the above -W options combined. This enables all the warn-
    ings about constructions that some users consider questionable, and
    that are easy to avoid (or modify to prevent the warning), even in
    conjunction with macros. This also enables some language-specific
    warnings described in C++ Dialect Options and Objective-C and
    Objective-C++ Dialect Options.

    The following -W... options are not implied by -Wall. Some of them
    warn about constructions that users generally do not consider question-
    able, but which occasionally you might wish to check for; others warn
    about constructions that are necessary or hard to avoid in some cases,
    and there is no simple way to modify the code to suppress the warning.

    -Wextra
    (This option used to be called -W. The older name is still sup-
    ported, but the newer name is more descriptive.) Print extra warn-
    ing messages for these events:

  7. #22
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    But yeah, I always assumed -W was some subset of -Wall. The "all" apparently is rather misleading.
    There was a message about that somewhere . . . I can't find it at the moment. Apparently, enabling all warnings is a bad idea, because some are very inefficient and give lots of false positives. The "-Wall" is what the GCC developers think is a good set of warnings to use, and you can enable and disable warnings from there.

    As for the name -- it's misleading, but it's a salute to Perl's -Wall, I believe.
    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. #23
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I don't know that I'll use -W regularly though, because as dwks said, some of them might be unwanted. But I'll give it a shot.
    Quote Originally Posted by laserlight View Post
    I do not recall there being a Chinese word that is pictorially equivalent to a #.
    Don't look at me, dwk's the one who knows chinese.

    But it (#) looks kind of like this: http://en.wikipedia.org/wiki/Image:C...r_Niu_Trad.png

  9. #24
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by robwhit View Post
    I don't know that I'll use -W regularly though, because as dwks said, some of them might be unwanted. But I'll give it a shot.
    No, what I meant was that enabling every single one of GCC's warnings would be a bad idea. However, even "-W -Wall" doesn't even come close to enabling all of its warnings. I highly recommend using "-W -Wall", or -Wextra if you don't mind the extra typing. (Sorry, couldn't resist.)

    [edit] Personally, I hate any extra typing at all. alias is fantastic. [/edit]

    Don't look at me, dwk's the one who knows chinese.
    I deny everything.

    But it (#) looks kind of like this: http://en.wikipedia.org/wiki/Image:C...r_Niu_Trad.png
    Sort of. If you squint really hard, take your glasses off (if you don't have glasses, borrow someone else's!), and walk as far backwards as the walls of the room you're currently in allow. (If you're outside . . . about 20 feet or so.)
    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. #25
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by dwks View Post
    No, what I meant was <<snip>>
    Oh, ok.
    I deny everything.


    Sort of. If you squint really hard, take your glasses off (if you don't have glasses, borrow someone else's!), and walk as far backwards as the walls of the room you're currently in allow. (If you're outside . . . about 20 feet or so.)
    I'm glad you agree with me.
    Last edited by robwhit; 03-02-2008 at 12:21 AM.

  11. #26
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by robwhit View Post
    I don't know that I'll use -W regularly though, because as dwks said, some of them might be unwanted.
    Personally, I'm a believer in enabling as many warnings (or, better, errors) as I can from a compiler, and then either modifying code to eliminate warnings or make sure I have a valid argument to ignore the warning. If I can, I do that with multiple compilers.

    With gcc, I generally use the "-Wall -pedantic-errors" command line options. I also add -ansi or -std=xxx options, depending on what version of the standard or updates I care about and my willingness to accept headaches (these options can trigger diagnostics from the standard headers).

  12. #27
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Personally, I'm a believer in enabling as many warnings (or, better, errors) as I can from a compiler ...
    So does matsp! http://cboard.cprogramming.com/member.php?u=26843 (And I.)

    I usually use "-W -Wall" for older versions of GCC, along with "-ansi -pedantic" for newer ones -- the last two can indeed cause warnings in standard header files in GCC 2.95, at least.

    I've never really had cause to try out other options like --std, except for --std=c99 occasionally. Oh, and a few things like -Wno-endif-labels to deal with the recent Debian SDL 1.2.12 annoyance . . . .
    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.

  13. #28
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Using a fine-grained error sieve and then choosing what to ignore seems good. But what do you do once you decide to ignore the warning?

    Do you just disable the warning? Then it can't be used for the rest of the file. And you have to remember which warnings you have on and which warnings you have off in any file.

    Maybe you split the affected code into its own file? Then you can compile each file with different warnings. But it increases the complexity of the project. Is it worth it?

    Then there are pragmas, but those aren't portable.

  14. #29
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I tend to disable the warning for entire files, because I don't like messing around with pragmas. Of course, I enable the warning occasionally and go through each occurrence of the warning to see if it's something I really want to ignore or not . . .

    If there were several warnings involved, I suppose it would probably be better to use pragmas. What do you do?
    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.

  15. #30
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I'd probably split it. But I want to know what others would do. Partly because I'm not sure if splitting the file would work in RL... unforeseen problems and stuff.
    Last edited by robwhit; 03-02-2008 at 01:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM