Namespaces
Variants
Actions

User talk:Newatthis

From cppreference.com

Contents

non-standard C in examples=

It's great to see the C section of this wiki getting some attention, but please verify your examples for standard conformance. At the very least, if you're using GCC or Clang, pass the -pedantic-errors switch to the compiler.

example from what I saw in more than one of the recently-posted examples, using clang:

test.c:7:5: error: plain '_Complex' requires a type specifier; assuming
      '_Complex double' [-Werror]
    complex z = cabs(1.0 + 2.0*I);
    ^
            double
/usr/include/complex.h:40:18: note: expanded from macro 'complex'
#define complex         _Complex
                        ^

--Cubbi (talk) 06:26, 10 February 2014 (PST)

Thanks for your feedback. I am using GNU GCC version 4.8.1 (www.onlinecompiler.com) to develop my examples. Then, I test using GCC 4.8 (C99) on the preview feature (www.cppreferemce.com) to be sure that there is no warning or error from the compiler. Is this process sufficient to meet standard conformance? I really am new-at-this. I welcome your guidance. Newatthis (talk) 11:50, 10 February 2014 (PST)

no, GCC is not standards-compliant by default. It needs the --pedantic switch to report standard violations as warnings or --pedantic-errors to make them fatal. You could use http://coliru.stacked-crooked.com/ and enter that switch at the compiler command line. --Cubbi (talk)
I was able to get a clean compile at coliru. I found -pedantic already entered on the command line. I made other changes with my limited knowledge of command-line arguments. In the end, I used this command:
    gcc -lm -O2 -Wall -pedantic -pthread main.cpp && ./a.out

I am about to move my source to cppreference to see whether it passes muster. Newatthis (talk) 12:49, 10 February 2014 (PST)

My example about csin() worked with a warning from Clang 3.4 (C99) but failed with GCC 4.8 (C99). The failure looked familiar, like the command line lacked "-lm". I continue to learn

how cppreference works. Newatthis (talk) 13:01, 10 February 2014 (PST)


language pages

When creating c/language/struct, you incorrectly copied 6.7.2.1/16 (casting for unions) instead of using 6.7.2.1/15 (casting for structs) and missed 6.7.2.1/18 (flexible array member). Please be more careful with the language spec. --Cubbi (talk) 07:43, 2 March 2014 (PST)

Many thanks. I continue to learn from your critique. I am still climbing the language-spec ladder. Next, I shall learn what 6.7.2.1/15 is.Newatthis (talk) 07:44, 3 March 2014 (PST)
6.7.2.1/15 is a paragraph from the C programming language ISO standard (from its current, 2011, revision in this case). This site's FAQ as well as the C language history page have links to the downloadable PDF. --Cubbi (talk) 18:31, 5 March 2014 (PST)
Many thanks. I see paragraphs 15,16,18 and understand my error. I also see the syntax at the bottom of page 112. When I started working on the page for "struct", I found "struct name {} instance ;" The word "name" has carried through the history of edits. The syntax on p.112 uses "identifier". For the purposes and goals of cppreference, would "identifier" be more appropriate? Newatthis (talk) 06:11, 6 March 2014 (PST)

Please keep the examples concise

An example you posted is far too large. Please remember to keep the examples concise - this wiki is a language/library reference, not a tutorial or a book. The book project is here. --Cubbi (talk) 14:19, 12 March 2014 (PDT)

fenv

I noticed that you're using the floating-point environment in your examples. Please keep in mind that the way you're using it invokes undefined behavior under 7.6.1 if the default state of the FENV_ACCESS pragama is off (implementation-defined but generally true since enabling it by default removes a lot of optimizations). To quote 7.6.1, "If part of a program tests floating-point status flags, sets floating-point control modes, or runs under non-default mode settings, but was translated with the state for the FENV_ACCESS pragma ‘‘off’’, the behavior is undefined. The default state (‘‘on’’ or ‘‘off’’) for the pragma is implementation-defined."

I've updated c/numeric/math/nextafter to use it correctly (and less excessively: examples are not meant to replace the reference documentation) and will update others when time allows. --Cubbi (talk) 09:42, 1 April 2014 (PDT)

Many thanks. You give me an opportunity to ask raise a couple of questions. First, your replacement example (as do many of my examples) yield undefined references followed by a ld error when compiling with "GCC 4.8 (C99)". Generally, compiling the same example with the alternate "clang 3.4 (C99)" works. Am I misusing cppreference.com's compiling facilities here? Secondly, regarding FENV_ACCESS, both compilers state that they are ignoring the "#pragma STDC FENV_ACCESS ON". clang even states that the pragma is not supported. This leaves me confused. With the compiler ignoring the pragma, how can we even think about using fenv.h? Newatthis (talk) 05:35, 2 April 2014 (PDT)
This wiki is a programming language reference, not a compiler reference. Some language features are not implemented by some compilers, or are implemented incorrectly, and it's not a reason to avoid them in the usage examples (actually my personal opinion is that such language features should definitely appear in the examples, to raise awareness). The lack of support for the STDC pragmas is a known bug in both compilers available at coliru: gcc #20785 clang #8100. To contrast, Oracle and IBM C compilers which I use at work, support it, as do some others. As for the ld error, we simply need to add -lm to GCC's compile options. --Cubbi (talk) 07:04, 2 April 2014 (PDT)
Many thanks for your explanation. I'll return to the examples with fenv.h and insert the pragma. Also, I'll reorient my focus to "programming language reference" from "compiler reference." I was using the two compilers provided to guide my examples. "To raise awareness" has been my personal opinion about the examples throughout my effort. Finally, perhaps cppreference.com will add "-lm" to its GCC compiler button so that I do not have to move to the clang compiler button to test my math.h examples. I always appreciate your feedback.Newatthis (talk) 07:24, 2 April 2014 (PDT)
I've added a -lm argument to the list of default arguments, but it doesn't seem to help for e.g. GCC on c/numeric/math/nextafter. If we figure out a good set of arguments that allows these examples to compile I'll be happy to make them the default. --Nate (talk) 07:57, 2 April 2014 (PDT)
-Wno-newline-eof should help clang and for gcc-4.8, -lm needs to be after main.cpp --Cubbi (talk) 08:28, 2 April 2014 (PDT)
Thanks, Cubbi. I've updated the arguments. --Nate (talk) 17:31, 3 April 2014 (PDT)
Thanks, Cubbi and Nate. Developing examples for math.h is now more convenient. On the other hand, not having GCC available for testing examples taught me that GCC and clang can behave differently with f-p exceptions. Newatthis (talk) 06:14, 4 April 2014 (PDT)

Please use descriptive names to all these new see-also links.

The links such as "types" or "atomic" are not meaningful, and even misleading, as they do not lead to a page about types, or a page about the type named "atomic" (they lead to the type support library page and the atomic operations library page, respectively. Please provide descriptive names. Assuming they are appropriate at all. --Cubbi (talk) 11:53, 4 June 2014 (PDT)

Thanks. I am studying your suggestion. Newatthis (talk) 12:17, 4 June 2014 (PDT)