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

1998/4/20-21 [Computer/SW/Languages/C_Cplusplus] UID:13988 Activity:high
04/20   I'd like to have C/C++ macro which would replace any comma
        seperated list of variables with an expression which uses those
        variables.  For example:
        DO_SOMETHING(a,b,c,d) becomes=> expression a,b,c,d
        DO_SOMETHING(a,b) becomes=> expression a,b
        In other words, I don't know how many variables may be used ahead
        of time.  Any ideas?
        \_ Just what we need, wannabe C programmers want to write stuff
           the langauge doesn't support.
        \_ Use Perl, you idiot.
        \_ this problem is a trival one.  just make your DO_SOMETHING
           a function that takes varargs.
           \_ Thought of that, but it needs to deal with declarations.
              Also, I'd like to be able to expand MACRO(x,y,z) to be:
              A::x = f();
              A::y = f();
              A::z = f();
              Where x,y,z are static const members.
        \_ What about instead of D(a,b,c,d),
           #define DO_SOMETHING expression
           Then you can just use:  DO_SOMETHING a,b,c,d
2025/05/24 [General] UID:1000 Activity:popular
5/24    

You may also be interested in these entries...
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;
	...
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/12/14-15 [Computer/SW/Compilers] UID:35291 Activity:moderate
12/14   If I have a C function like this
        void foo(void) {
          static const char unused1[] = "one";
          const char * const unused2 = "two";
          ...... some code ......
          return;
	...
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/8/10-11 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Compilers] UID:32805 Activity:high
8/10    C question.  Is there anything wrong with the following?
        const my_struct_t **pp;
        pp = malloc(sizeof(my_struct_t *));
        pp = realloc(pp, sizeof (my_struct_t *) * 2);
        "gcc -Wall" doesn't complain.  But the M$ compiler (cl.exe) complains
        about the realloc line:
	...
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
	...
2004/5/28-29 [Computer/SW/Compilers] UID:30481 Activity:nil
5/28    I just found out that bison inserts these lines of code
                #ifndef __cplusplus
                #ifndef __STDC__
                #define const
                #endif
                #endif
	...
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
	...