Preprocessor macro substitution

Discussion in 'C Programming' started by Default User, Jul 10, 2008.

  1. Default User

    Default User Guest

    I've never really done too much stuff with macros. I have a program
    here where an target server address is automatically generated from
    WSDL. For testing, I want to use a localhost address.

    I could do it by overriding the endpoint explicitly, but I'd rather
    not. It would be cleaner to define a local testing environment.

    My first thought was just to use a #define, like:

    #define foo.bar localhost

    However, that's no good as foo.bar tain't a legal identifier with that
    '.' in it. Anyone have some clever preprocessor way to get what I want?





    Brian
    Default User, Jul 10, 2008
    #1
    1. Advertising

  2. Default User

    Default User Guest

    Eric Sosman wrote:

    > Default User wrote:
    > > I've never really done too much stuff with macros. I have a program
    > > here where an target server address is automatically generated from
    > > WSDL. For testing, I want to use a localhost address.
    > >
    > > I could do it by overriding the endpoint explicitly, but I'd rather
    > > not. It would be cleaner to define a local testing environment.
    > >
    > > My first thought was just to use a #define, like:
    > >
    > > #define foo.bar localhost
    > >
    > > However, that's no good as foo.bar tain't a legal identifier with
    > > that '.' in it. Anyone have some clever preprocessor way to get
    > > what I want?

    >
    > What you haven't told us is where you're starting: How do
    > you get hold of the server address to begin with? "From WSDL"
    > doesn't seem to me a very complete description ...


    I didn't want to get too deeply into the details, but evidently I was
    insufficiently thorough. The service address is specified in the WSDL.
    A utility processes this and generates some C headers and source files.
    Included in some places is the "endpoint" or target address. If you
    don't provide an overriding address, then this is the one that is used.
    So there will things like this:

    if (!soap_endpoint)
    soap_endpoint = "http://foo.bar:8080"

    As it is generated code, I can't change that. I can provide an
    endpoint, but that's fragile, as it then requires a manual update if
    the WSDL is changed.

    I can also do something like:

    soap_endpoint = END_POINT;

    Then for testing purposes:

    #ifdef TESTING
    #define END_POINT "http://localhost:8080"
    #else
    #define END_POINT NULL
    #end



    It's not as clean, but would work.



    Brian
    Default User, Jul 11, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tmponko
    Replies:
    3
    Views:
    5,191
    tmponko
    Jan 1, 2004
  2. Cronus
    Replies:
    1
    Views:
    634
    Paul Mensonides
    Jul 15, 2004
  3. Johan

    macro substitution

    Johan, Oct 29, 2004, in forum: C++
    Replies:
    2
    Views:
    1,652
    David Harmon
    Oct 29, 2004
  4. Malcolm

    Macro Substitution Help Request

    Malcolm, Sep 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    574
    Keith Thompson
    Sep 11, 2005
  5. Chad
    Replies:
    3
    Views:
    451
    Singamsetty
    Oct 18, 2005
Loading...

Share This Page