Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:42:32+00:00 2026-06-15T21:42:32+00:00

In my C application, I have a logging method similar to this: void logError(const

  • 0

In my C application, I have a logging method similar to this:

void logError(const char* module, const char* message, ... );

When this method is called, callers often do something like the following:

logError("foo", "bar");

// or even

#define FOOMODULE "foo"
logError(FOOMODULE, "bar");

No matter how the char* module gets passed in, the char* is static memory stored in the application binary.

My question is, does the compiler/linker collapse all instances of a statically declared string into a single declaration? As such, is it valid to assume that comparing the pointers ("foo" == FOOMODULE) of my statically declared strings will always work as expected (assuming, of course, that the strings are equivalent as in my example above and that both are indeed statically allocated in the app’s binary)?

I’m working on a way to filter on log messages as they come in. For example, perhaps I only want to see log messages from a single ‘module’. It would be great to compare the pointers and not each byte in the string when deciding if I want to actually print a given log message.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:42:33+00:00Added an answer on June 15, 2026 at 9:42 pm

    It will often work, but it is not guaranteed and such a comparison should not be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, I have a 'logging' window, which shows all the logging, warnings,
I have an application that records activity in a table (Oracle 10g). The logging
I have a simple ticket logging application build on LAMP. I am currently playing
I have an existing application which does all of its logging against log4j. We
I have a console application that should do best effort logging to a database
We have several choices for logging in our .NET (C#) server application. We are
I have many domain classes in my application an for Audit logging I need
I have been attempting to get log4net logging in my asp.net web application with
I have written a class that will handle internal logging in my application. Now
I have a little issue with my hibernate logging configuration. In our application, we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.