Berkeley CSUA MOTD:Entry 30054
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2004/5/6 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Compilers] UID:30054 Activity:moderate
5/6     I'm trying to use "#define errno WSAGetLastError()" in a winsock
        file, but the compiler says errno is already #def'ed.  I can't
        just run cpp on the file--it's a crappy ide-based compiler--so
        I'd like to do something like printf("errno"), but of course that
        just prints "errno" instead of the preprocessor's notion of what
        errno is #def'ed to.  What should I do instead?
        \_ errno is already defined because it's part of the c-library.  Do
           One of the following:
           call perror() : This will print an error description to stderr
           use strerror(errno) to get the error string and print it however you
           want
           use strerror_r(errno, mybuffer, mybuffer_length) to put the error
           string into your buffer mybuffer
           \_ Sorry, should have explained myself a bit more-- this is a socket
              protocol wrapper file that's compiled into windows, unix, cygwin,
              and vxworks objects.  I'm doing a lot of
                rc = select(...);
                if (rc && EWOULDBLOCK == errno) { /* handle blocking error */
              so I really need the #def to work correctly.  I could just undef
              errno for winsock and then re-#define it, but I'd like to know
              what it evaluates to first.
        \_ Many compilers allow you to compile only the preprocessor step.  For
           instance, with Visual C++ 6 you can add "/E" to the compile options
           and you'll get the preprocessor output in the build window (and .plg
           file).
        \_ May I ask why you need to alias WSAGetLastError() to the preexisting
           #define errno?  Why not use a different label?
           \_ Every library except winsock uses errno to report the error, so it
              seemed relatively natural to keep it consistent.  I guess I could
              use MY_FOO_ERROR instead, but that would require a #else to the
              #ifdef _WINSOCK_H.  Also, I'm kinda curious how to print the
              evaluated macro at runtime.
        \_ if you really wanted, you could #undef errno first.  I don't see
           what using a crappy IDE-based compiler has to do with anything;
           it doesn't stop you from running cpp.  Anyhow, if you want to see
           what errno is #define'd to, see this:
                http://www.eskimo.com/~scs/C-faq/q11.17.html
           --jameslin
           \_ Thanks, this is exactly it.  Errno was #def'ed to *_GetErrno()
              and I didn't want to #undef it if it was already "magically" set
              to WSAGetLastError by <winsock.h>.  Also, running cpp on the file
              says that errno was #def'ed to *__errno().
2025/05/24 [General] UID:1000 Activity:popular
5/24    

You may also be interested in these entries...
2005/4/29-5/1 [Computer/SW/Languages/Perl] UID:37411 Activity:moderate
4/29    I need help getting information off a web site.  A page presents
        information about an item in locations spread througout the page.
        Each page presents information about one item. What is a quick and
        easy way to go through several pages, capture all the information
        related to each item, and put them into a spreadsheet with a unique
        index?  I think this might be possible by scraping the screen, but how
	...
2004/11/5-7 [Computer/SW/Languages/C_Cplusplus] UID:34697 Activity:high
11/5    In C, why is the "offsetof" macro defined to be of type size_t but not
        ptrdiff_t?  Thx.
        \_ Probably because ptrdiff_t is signed and size_t isn't.
           \_ How does being signed make ptrdiff_t less portable?
              \_ Imagine a 16-bit C implementation, where int is 16 bits, long
                 is 32 bits, and the maximum object size is 64k - 1.  size_t
	...
2004/8/30-31 [Computer/SW/Languages/C_Cplusplus] UID:33228 Activity:high
8/30    Ok this is pretty basic but... is there a way to "escape" text to
        avoid it being substituted by C preprocessor macro expansion?
        \_ Wouldn't that functionality make C preprocessing as powerful as
           lisp's quasiquote/escape? -- ilyas
           \_ Squish!  Isn't it illegal to talk about lisp on the motd?!
        \_ In general no.
	...
2004/8/18-19 [Computer/SW/Languages/C_Cplusplus] UID:32995 Activity:very high
8/18    Doesn't math.h define min() and max() functions?  What should I include
        to get them?  I'd rather not do the (a < b) ? a : b thing.  Thx
        \_ No.  Many programmers define it as a new macro.  Don't know what
           gcc people do, offhand.
        \_ OS X has fmin(3)/fmax(3) which conform to ISO/IEC 9899:1999(E).
           Linux might have these too.
	...
2004/7/13-14 [Computer/SW/Languages/C_Cplusplus] UID:32265 Activity:high
7/12    Someone please explain the following?
        ((size_t )& ((SomeVar *)0)->Field);
        \_ It's a hideous abuse of C++ syntax and results in undefined
           behavior.  It appears to be an attempt to find out the offset of the
           member "Field" in the class/struct type SomeVar.  Ow, ow ow.
           \_ This is actually not undefined, in C or C++.  It is hideous,
	...
2004/7/5 [Computer/SW/Languages/Perl] UID:31164 Activity:high
7/4     Is there something like a macro in Perl?  Couldn't find any in
        the Camel book.
        \_ If you truly need macros in Perl, you probably want AUTOLOAD.
           Of course, if you truly need macros, Perl is the wrong language for
           what you are doing.  -- ilyas
        \_ I don't know perl, but don't almost all interpreted languages have
	...
2003/8/29-2004/2/14 [Computer/SW/Languages/C_Cplusplus] UID:12260 Activity:nil
2/13    Where can I get c macro specifications? What keywords to look in
        google?
        \_ You might also want to find a good book on the specification of
           English, so you don't have to look like an ignorant tool asking
           a simple C question.
        \_ what do you want to know?  There's the C language spec that you
	...
2003/11/26-27 [Recreation/Dating, Computer/SW/OS/FreeBSD] UID:11228 Activity:kinda low 88%like:29671
11/26   what preprocessor macro is defind on FreeBSD so that I can write
        conditional code only for FreeBSD? i am using gcc...
        What about solaris? Thanks.
http://www.chnlove.com
http://www.chnlove.com/my/profile.php?womanid=GZB271199
http://www.chnlove.com/my/profile.php?womanid=GZB271195
	...
2003/11/26-27 [Computer/SW/OS/FreeBSD] UID:29671 Activity:nil 88%like:11228
11/26   what preprocessor macro is defind on FreeBSD so that I can write
        conditional code only for FreeBSD? i am using gcc...
        What about solaris? Thanks.
        \_ You can use __FreeBSD__ and __sun to tell the difference between
           FreeBSD and Solaris; you can also use __i386 and __sparc if you
           want to know the CPU type.  (These all work with Sun's C compiler
	...
2003/8/9-11 [Computer/HW/CPU] UID:29294 Activity:moderate
8/10    I just build a AMD2500+ computer and overall I'm pretty happy with
        it. However it seems to output a lot more heat than my P4. Is this
        normal?
        \_ yes AMD cpus consume more power and run hotter
        \_ I hope you're not settling for a stock fan, and you have at least
           2-3 case fans.
	...
2002/12/5 [Computer/SW/Apps] UID:26711 Activity:nil
12/4    M$ Excel qn: I have a column of 10000 numbers.  Is there any easy way
        to create another column of 1000 numbers where each number is the sum
        (or average) of the corresponding 10 numbers in the first column?  Thx.
        \_ should be do-able with the Fill-Down menuu item.
        \_ what exactly do you mean by corresponding 10 numbers?
        \_ he means you have column A which has "1,2,3,4,5,6,7,8,9,10", and
	...
2014/1/14-2/5 [Computer/SW/Languages/C_Cplusplus] UID:54763 Activity:nil
1/14    Why is NULL defined to be "0" in C++ instead of "((void *) 0)" like in
        C?  I have some overloaded functtions where one takes an integer
        parameter and the other a pointer parameter.  When I call it with
        "NULL", the compiler matches it with the integer version instead of
        the pointer version which is a problem.  Other funny effect is that
        sizeof(NULL) is different from sizeof(myPtr).  Thanks.
	...
2013/4/29-5/18 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Compilers] UID:54665 Activity:nil
4/29    Why were C and Java designed to require "break;" statements for a
        "case" section to terminate rather than falling-through to the next
        section?  99% of the time poeple want a "case" section to terminate.
        In fact some compilers issue warning if there is no "break;" statement
        in a "case" section.  Why not just design the languages to have
        termination as the default behavior, and provide a "fallthru;"
	...
2012/12/18-2013/1/24 [Computer/SW/Languages/Perl] UID:54561 Activity:nil
12/18   Happy 25th birthday Perl, and FUCK YOU Larry Wall for fucking up
        the computer science formalism that sets back compilers development
        back for at least a decade:
        http://techcrunch.com/2012/12/18/print-happy-25th-birthday-perl
        \_ I tried to learn Perl but was scared away by it.  Maybe scripting
           lanauages have to be like that in order to work well?
	...
2011/3/7-4/20 [Computer/SW/Languages/C_Cplusplus] UID:54056 Activity:nil
3/7     I have a C question.  I have the following source code in two identical
        files t.c and t.cpp:
                #include <stdlib.h>
                int main(int argc, char *argv[]) {
                  const char * const * p1;
                  const char * * p2;
	...
2010/1/22-30 [Computer/HW/Laptop, Computer/SW/OS/OsX] UID:53655 Activity:high
1/22    looking to buy a new development laptop
        needs ssdrive, >6 hr possible batt life, and runs linux reasonably
        Anyone have a recommendation? Thx.
        \_ thinkpad t23 w ssdrive and battery inplace of drive bay
        \_ Ever wondered what RICHARD STALLMAN uses for a laptop?  Well,
           wonder no more!
	...
2010/1/12-29 [Computer/SW/Apps/Media] UID:53627 Activity:kinda low
1/12    How do I get a job NOT related to internet DNS social network cloud
        twitter GOOG EC2 amazon API ???
        \_ A CS job not related to API?
        \_ Chip design, or maybe software that does chip design. What is
           your major? How about game developer?
        \_ DNS? DNS? What era ado you live in? I agree that social network
	...
2009/8/31-9/9 [Computer/SW/Compilers] UID:53312 Activity:nil
8/31    I'm trying to learn ActionScript, like a step by step tutorial.
        The site at http://www.actionscript.org/resources/categories/Tutorials/Flash/Beginner
        isn't well organized. It doesn't explain how to get started with
        an editor, compiler, IDE. And should I even learn AS2 when you can
        learn AS3? Is Adobe Flash CS4 >>> CS3 or just CS4 > CS3?
	...
2009/5/6-14 [Computer/SW/Languages/Perl, Computer/SW/Languages/Web] UID:52961 Activity:kinda low
5/6     I'm sure you've seen web sites that distribute software by making
        a user fill out a form and then e-mailing the user a randomly
        generate link to the software that works just once. What software
        is used to do this? I'd like to distribute software in such a way.
        \_ "Software"?  What web server/web application environment
           are you using?
	...
2009/2/28-3/11 [Computer/SW/Compilers] UID:52661 Activity:nil
2/28    I'm looking for a recommendation of a compiler/IDE to use to
        develop C/C++ code under Linux. In school, we used jove/gcc and
        I still use emacs/vi and gcc to this day. However, it is really
        lacking. Under Windows I tried Visual Studio and there were some
        really nice things about it, although it was so overwhelming that
        after 6 months of occasional use I still didn't really know what I
	...
Cache (342 bytes)
www.eskimo.com/~scs/C-faq/q11.17.html
You can use something like the following two-step procedure to force a macro to be expanded as well as stringized: #define Str #x #define Xstr Str #define OP plus char *opname = Xstr(OP); An equivalent circumlocution is necessary with the token-pasting operator ## when the values (rather than the names) of two macros are to be concatenated.