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 8141581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:33:30+00:00 2026-06-06T12:33:30+00:00

I have a program with a set of input and a set of out

  • 0

I have a program with a set of input and a set of out variables that I exchange with an Apache/PHP webpage using XML. The webpage is where users can see what is configured/going on and can change settings.

When I pass the XML to the PHP program (we use Unix_domain Sockets) I add a lot of meta-information about the settings and indicators I’m passing to him. Things like datatype, min, max, default, read/write privileges, etc.

<temperature datatype="INT32" min=-"40" max="150" permissions="R/O">25</temperature>

I need to know the metadata about each of my variables as I build the outbound xml. I though a good way to do this wouldbe to create a class VarInfo which I’d associate to each variable. Insted of storing the variable name as the key in the map (not sure I can always know the variable name) I thought of making the key be the pointer to the variable and the value be the pointer to a VarInfo object for that variable. Only way I know to store mixed pointer types is to cast them all to void*. So, something like:

bool cmpr( void* a, void*b) { return (long)a < (long)b;};
std::map<void*,VarInfo*,cmpr>   VarMap;

int        temperature;
VarInfo    vi_temperature;

VarMap[(void*)&temperature] = &vi_temperature;

Doing this create a bunch of errors about declaring the map.

expected a type, got ‘cmpr’ ACT_iod.cpp
Invalid template arguments  ACT_iod.cpp line 40 Semantic Error
invalid type in declaration before ‘;’ token
type/value mismatch at argument 3 in template parameter list for 
    ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’  

So, can someone suggest how I might get this working and probably also suggest a better way to store the metainfo? Still thinking about changing to std::string’s as the key.

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-06T12:33:32+00:00Added an answer on June 6, 2026 at 12:33 pm

    The third parameter of the std::map should be the type of the comparator. As one fix you could make cmpr a functor (which is often the preferred aproach due to its inlinablility):

    struct cmpr {
      bool operator()(void* a, void* b) {...}
    }
    std::map<void*,VarInfo*,cmpr>   VarMap;
    

    The other alternative is to use the type of the function pointer (bool(*)(void*, void*) iirc) and give the pointer to the actually used function as a parameter of the constructor:

    bool cmpr( void* a, void*b) { return (intptr_t)a < (intptr_t)b;}
    std::map<void*,VarInfo*,bool(*)(void*, void*)>   VarMap(&cmpr); 
    

    Edit: now that I think about it: The default comparison for pointers is < anyways, so you could just use std::map<void*, VarInfo*> which has the benefit of being more portable. Generally you should avoid casting pointers to long. Avoid pointer to integral casts when possible, otherwise using intptr_t, uintptr_t or size_t is a much better idea, since long is not guaranteed to be big enough to hold a pointer (and long is indeed 32bit on some 64bit platforms).

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

Sidebar

Related Questions

I'm trying to multithread something and i have my program set up such that
I have a program that needs a lot of memory and want to set
I have a program that works with multiple threads. For each I set uncaught
I have a working program in C++ that generates data for a Mandelbrot Set.
I have a mixed mode C++-CLI program in Visual Studio 2005 that is set
Currently I have a program that takes as input a folder that contains .MPP
I have a set of data that shows users, collections of fruit they like,
I have an ASP.NET Web Form (C#) that users fill out, it has a
I have a program with a GUI interface whose initial set-up I need to
I have an existing program we've developed as a large set of Eclipse plugins.

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.