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

2004/9/20-21 [Computer/SW/Languages/C_Cplusplus, Uncategorized/German] UID:33644 Activity:moderate
9/20    C question.  If I have
                #define NAME    FOO
        is there any way to use NAME to create a string "FOO"?  Thanks.
        \_ Do you mean #define NAME "FOO" ?  Or do you want to declare a
           variable?  Can you show NAME used in a sample line of code?
           \_ What I want is something like, say,
                strncpy(myArray, $$NAME, sizeof myArray);
              and I want $$NAME to compile to "FOO".
              \_ What's wrong with a const char* string? You want
                 #define NAME "FOO".
                 \_ Because the #define is at somewhere else that I can't
                    change.
        \_ Short answer yes, but it involves so much hackery that it's not
           worth it.  The link below used to explain how but it's 404'd now,
           maybe you can google cache for the original.
http://userpage.fu-berlin.de/~ram/pub/pub_isews26/c_preprocessor_applications_en
           http://tinyurl.com/6xmuz
           \_ ow ow ow! (the relevant code)
              //enumstring.c
              #include <stdio.h>
              #define NAMES C(RED)C(GREEN)C(BLUE)
              #define C(x) x,
              enum color { NAMES TOP };
              #undef C
              #define C(x) #x,
              const char * const color_name[] = { NAMES };
              int main( void )
              { printf( "The color is %s.\n", color_name[ RED ]);
                printf( "There are %d colors.\n", TOP ); }

              (stdout)
              The color is RED.
              There are 3 colors.
        \_ Am I missing something? What's wrong with using #NAME to stringify?
           e.g. #define str(x) #x
           \_ Then str(NAME) gives me "NAME", but I want "FOO".
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;
	...
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/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/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/12/8-9 [Computer/SW/Languages/C_Cplusplus] UID:11356 Activity:nil
12/8    c++ question, how do I overload << in my class so it will handle
        endl? ie: myclass << "some string" << endl
        I know how to do the "some string" part:
                myclass & operator << (const char * s);
        what about endl?
        Thanks!!
	...
2003/9/10 [Computer/SW/Languages/C_Cplusplus] UID:29529 Activity:nil
9/10    Stupid question: how do I reference a C callback?
        int mycompare(void const *a, void const *b) { ... }
        qsort(msg, sizeof(Msg), numMsgs, mycompare);
        I get
        "Type error in argument 4 to `qsort'; calling convention mismatch."
        \_ There's nothing wrong in the you reference it.  However, you should
	...
2003/4/22-23 [Computer/SW/Languages/C_Cplusplus] UID:28189 Activity:insanely high
4/22    Anyone know a good link that explains all of C++'s use of the
        keyword mconst?
        \_ http://www.parashift.com/c++-faq-lite
           Search for const in the text box.
           Search for mconst in the text box.
           \- perfection
	...
2002/7/13-15 [Computer/SW/Languages/C_Cplusplus] UID:25351 Activity:moderate
7/13    how do i pass variables to the system in C ?  e.g.
         system("echo input is %s", argv[1]);
        results in "input is %s" but I want the system to see argv[1]
        (I know i can just use printf, but not for what i really want to do).
        \_ sprintf into array, pass array to system?
        \_ so write your own function that takes a variable number of
	...
2001/9/23-24 [Computer/SW/Languages/C_Cplusplus] UID:22600 Activity:moderate
9/23    let's say there's a C library you want to use called libmdn.so.
        I think to load it you'd go something like:
        static { System.loadLibrary("mdn"); }
        However, let's say that a function call looked like this:
        mdn_result_t mdn_encodename(int actions, const char
        *from, char *to, size_t tolen)
	...
2001/3/17-18 [Computer/SW/Languages/C_Cplusplus] UID:20827 Activity:high
3/16    Why does so much C sample code use #define instead of const?
        \_ because any good C code will use a bunch of preprocessor
           anyways. you can't be a good C programmer and eschew the
           preprocessor. For that, you need a language which fills those
           gaps with other constructs (c++ templates go a long way to
           obviate the need for preprocessor for example). you
	...
2000/6/21-22 [Computer/SW/Languages/C_Cplusplus] UID:18506 Activity:very high
6/20    I have a variable inside a struct.  I want to be able to initialize
        that variable ONCE and not write to it again.  Any subsequent writes
        should not be permitted.  Is there a way to do that in C?  I know
        about "const int foo = 5;" but the value I need to pass in is dynamic
        and happens at runtime.  Declaring a variable as const doesn't let
        me assign anything to it at all.  Thanks.
	...
2005/8/18-19 [Uncategorized/German] UID:39171 Activity:moderate
8/18    Das haben wir gleich.
        In Ordnung.
        Ihr entkommt mir nicht!
        \_ Heil cherman john guy, stat!  Please show this person that a _real_
           German haiku would get the syllables right.  -John
           \_ Obviously, you don't use Yahoo Messenger's new International
	...
2005/7/15-16 [Uncategorized/German] UID:38648 Activity:nil
7/15    OTM arekordjahr 2004.
        http://csua.org/u/cpu [ reuters ]große Politik des
        \_: "Mexikaner verfing sich durch die STAATRANDPATROUILLEN, die zu
           enter das Land illegal werden normalerweise sofort zu
           their. Viele warten einfach einen Tag und versuchen dann sneak
           theland wieder.",
	...
2005/7/15-16 [Uncategorized/German] UID:38649 Activity:nil
7/15    ist motd der kchangs Index unten oder es es gerade ich? tut sonst
        find dieses Befreien?
        \_ wie. Wenn Sie nicht aus jetzt dem ' dargestellt haben, der
           useless, konnten Sie so glauben.
        \_, was Mittel "niederwirft"? Es gibt viele Eigenschaften, die man
           \_ http://www.urbandictionary.com/define.php?term=down
	...
2005/5/3 [Uncategorized/German] UID:37503 Activity:nil
5/3     sehen Sie, ich sind nicht das einzige, wer dachte, daß es war eine
        http://www.pnionline.com/dnblog/attytood/archives/001795.html
        Will Bündel ist der ältere politische Verfasser für das Philadelpia
        Daily Nachrichten.
        \_ können Sie einem Philadelphian nie vertrauen. Goddamn "brotherly
        \_, möglicherweise, welches die Hauptströmungsmittel durch
	...
2005/5/3 [Uncategorized/German] UID:37504 Activity:nil
5/3     http://www.msnbc.msn.com/id/7693580/site/newsweek
        "Beijing Concensus": China, das politisch überlistet und
        diplomatically unpassende Bush-führende US.
        \_ "Japaner haben nicht sich tadellos benommen, aber sie haben sich
           several Zeiten für ihren Kriegangriff."
           Also, mein Messwert des Artikels ist, daß politisch China hat
	...
2005/5/3 [Uncategorized/German] UID:37505 Activity:nil
5/3     so lang, Aktienoptionen:
        http://money.cnn.com/2005/05/03/technology/microsoft_options.reut
        \_ I hörte ein Gerücht, das bei Yahoo, sie das Suchen geringfügig
           excuses, zum der alten Timer abzufeuern, die Lose Aktienoptionen
           This ist von einem Systemverwalter bei Yahoo, also ist es
           probably zutreffend.
	...
2005/5/3 [Uncategorized/German] UID:37506 Activity:nil
5/3     der Unterschied zwischen Tony Blair und Dubyas Rathaussitzungen:
        Late letzte Woche, bei einem seiner rituellen grillings - dieses
        television Programm "Fragezeit" - die Publikum booed als er
        appeared und wurde dann sogar feindlicher. "das eine Lüge ist! Sie
        to dieses Land und das ist, warum wir nicht Sie stützen können!"
        young Mann, Blair von die Intelligenz ungefähr übertreiben
	...
2004/3/5 [Uncategorized/German] UID:12532 Activity:high Edit_by:auto
                              ACHTUNG!!!!
      Das Soda ist nicht fuer warezhausen oder mailspammen.  Ist easy
   pissenoffen die rooten und overloaden das wallall mit die fuck-youen
  und die yer-momen.  Ist nicht fuer gewerken bei das majorfuckentwinken.
      Das diskhoggen pornseeren keepen das bandwit-hosen hands in das
            pockets muss.  Relaxen und watchen das wallflamen.
	...
2002/3/28 [Uncategorized/German] UID:24253 Activity:nil
3/26    Ich bin der Nebel.  Mit mir muss rechnen.  Der auf das Wasser
        hinausfa"hrt.  Tausend Jahren hat man keinen gesehen.  Der ihn
        der Luft herumfliegen will.  Wer bist du, eigentlich?
        \_ Wat da hel?
        \_ ACHTUNG! Alles touristen und non-technischen peepers!
           Das machine control is nicht fur gerfinger-poken und mittengrabben.
	...
Cache (2430 bytes)
userpage.fu-berlin.de/~ram/pub/pub_isews26/c_preprocessor_applications_en
Um eine dauerhafte Verbindung mit einer Seite herzustellen, mu statt dessen die kanonische URI einer Seite verwendet werden. Diese kanonische URI wird oben auf einer Seite angegeben und kann auch daran erkannt werden, da sie den Text "purl" enthlt. Die gewnschte Quelle kann wahrscheinlich ausgehend von der folgenden Startseite wiedergefunden werden. Zu der verlangte URI konnte leider keine Ressource gefunden werden. Am Anfang wurde die wahrscheinlichste Ursache fr dieses Problem benannt. Falsche Links oder technische Strungen knnten ein andere Ursache sein. Stefan Ram bittet zu entschuldigen, da die gewnschte Seite nicht direkt erreicht werden konnte. Eine gesuchte Seite von Stefan Ram kann oft auch mit der Suchmaschine Google (TM) gefunden werden. Hint regarding the URI used Possibly a URI (address) with temporary short term lifetime was used (a URI containing "userpage"). To create a permanent link to a page the canonical URI has to be used. It is given at the top of a page and can be recognized by the text "purl" contained in it. The desired resource might possibly be found starting at the following homepage. Above the most likely cause for the problem was specified. Wrong links or technical failures are other possible explanation. Stefan Ram asks to please accept his apologies for the inability to deliver the resource requested. A wanted page of Stefan Ram can often be found using the Google (TM) search engine. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable. Von der Stefan-Ram-Startseite ausgehend finden sich oft noch mehr Informationen zu Themen, die auf einer Seite angesprochen wurden. Formular fr diese Seite betreffende Mitteilungen an den Herausgeber | Der Urheber dieses Textes ist Stefan Ram. Schlsselwrter zu dieser Seite/relevant keywords describing this page: slrprd slrprd721073 stefan_ram:721073 Hinweis zur verwendeten URI Stefan Ram, Berlin, and, or, near, slrprd, slrprdqxx, slrprddoc, slrprd721073, slrprddef721073, Erklrung, Beschreibung, Info, Information, Hinweis, Der Urheber dieses Textes ist Stefan Ram.
Cache (2430 bytes)
tinyurl.com/6xmuz -> userpage.fu-berlin.de/~ram/pub/pub_isews26/c_preprocessor_applications_en
Um eine dauerhafte Verbindung mit einer Seite herzustellen, mu statt dessen die kanonische URI einer Seite verwendet werden. Diese kanonische URI wird oben auf einer Seite angegeben und kann auch daran erkannt werden, da sie den Text "purl" enthlt. Die gewnschte Quelle kann wahrscheinlich ausgehend von der folgenden Startseite wiedergefunden werden. Zu der verlangte URI konnte leider keine Ressource gefunden werden. Am Anfang wurde die wahrscheinlichste Ursache fr dieses Problem benannt. Falsche Links oder technische Strungen knnten ein andere Ursache sein. Stefan Ram bittet zu entschuldigen, da die gewnschte Seite nicht direkt erreicht werden konnte. Eine gesuchte Seite von Stefan Ram kann oft auch mit der Suchmaschine Google (TM) gefunden werden. Hint regarding the URI used Possibly a URI (address) with temporary short term lifetime was used (a URI containing "userpage"). To create a permanent link to a page the canonical URI has to be used. It is given at the top of a page and can be recognized by the text "purl" contained in it. The desired resource might possibly be found starting at the following homepage. Above the most likely cause for the problem was specified. Wrong links or technical failures are other possible explanation. Stefan Ram asks to please accept his apologies for the inability to deliver the resource requested. A wanted page of Stefan Ram can often be found using the Google (TM) search engine. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable. Von der Stefan-Ram-Startseite ausgehend finden sich oft noch mehr Informationen zu Themen, die auf einer Seite angesprochen wurden. Formular fr diese Seite betreffende Mitteilungen an den Herausgeber | Der Urheber dieses Textes ist Stefan Ram. Schlsselwrter zu dieser Seite/relevant keywords describing this page: slrprd slrprd721073 stefan_ram:721073 Hinweis zur verwendeten URI Stefan Ram, Berlin, and, or, near, slrprd, slrprdqxx, slrprddoc, slrprd721073, slrprddef721073, Erklrung, Beschreibung, Info, Information, Hinweis, Der Urheber dieses Textes ist Stefan Ram.