I am using Borland C++ Builder 6, on an XP PC. When I compiled a software unit that made reference to crtdbg file, I received the following error messages:
/* Borland version of Microsoft CRTDBG.H header file
This is used by MFC and ATL.
*/
/*
* C/C++ Run Time Library - Version 11.0
*
* Copyright (c) 1999, 2002 by Borland Software Corporation
* All Rights Reserved.
*
*/
/* $Revision: 9.4.2.1 $ */
#ifndef _INC_CRTDBG
#define _INC_CRTDBG
#ifndef __UTILCLS_H
#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Prototypes for internal RTL helper functions: */
void _ErrorMessage(const char *__message);
void _ErrorExit (const char *__message);
#ifdef __cplusplus
}
#endif
/* Asserts */
#if !defined(_DEBUG)
#define _ASSERT(expr) ((void)0)
#define _ASSERTE(expr) ((void)0)
#else /* !defined(_DEBUG) */
#define _ASSERT(a) _ASSERTE(a)
#define _ASSERTE(expr) do { \
if (!(expr) && __ASSERTE_Helper (#expr, __FILE__, __LINE__) == IDCANCEL) \
::DebugBreak(); \
} while (0)
/* _ASSERTE helper routine returns: MB_YES, MB_NO or MB_CANCEL
*/
__inline int __ASSERTE_Helper(bool expr, char *file, int line)
{
TCHAR msg[256*2];
::wsprintf(msg, _T("%s failed - %s/%d"), expr, file, line);
/* throw (msg); */
_ErrorExit(msg);
return 0; /* Never really gets here */
}
#endif /* !defined(_DEBUG) */
#endif /* __UTILCLS_H */
#endif /* _INC_CRTDBG */
[C++ Error] crtdbg.h(52): E2268 Call to undefined function '_T'
[C++ Error] crtdbg.h(52): E2034 Cannot convert 'int' to 'const char *'
[C++ Error] crtdbg.h(52): E2340 Type mismatch in parameter 2 (wanted 'const char *', got 'int')
What's wrong with it?
You should add the TCHAR.H include (or a Borland equivalent).
_T() is a macro that converts 8-bit strings into wide character format.
Related
I have installed Imlib2 on my computer, however doing the example program as below (having changed the line for loading files to include the error code) I keep getting the error code 4.
/* standard headers */
#include <X11/Xlib.h>
#include <Imlib2.h>
#include <stdio.h>
#include <string.h>
/* main program */
int main(int argc, char **argv)
{
/* an image handle */
Imlib_Image image;
Imlib_Load_Error err;
/* if we provided < 2 arguments after the command - exit */
if (argc != 3) exit(1);
/* load the image */
image = imlib_load_image_with_error_return(argv[1],&err);
if(err) printf("load error:%d",err);
/* if the load was successful */
if (image)
{
char *tmp;
imlib_context_set_image(image);
tmp = strrchr(argv[2], '.');
if(tmp)
imlib_image_set_format(tmp + 1);
imlib_save_image(argv[2]);
}
}
I have a simple program which calls getaddrinfo() and freeaddrinfo().
I run valgrind on it, and it shows that there is no memory leak.
in use at exit: 0 bytes in 0 blocks
total heap usage: 108 allocs, 109 frees
However, I wrote a memory debugger named memleax which attaches the target process and traps at malloc() and free() to detect memory leak. I use memleax to detect the getaddrinfo() program, and it catches free() only 43 times.
Then I hook the malloc() and free() by malloc-hooks,
and it also shows free() only 43 times.
So my question is that, what is the difference between valgrind and hooking-malloc?
Original code:
#include <sys/types.h>
#include <string.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
int main()
{
struct addrinfo *aihead;
sleep(4);
printf(" --- getaddrinfo ---\n");
int error = getaddrinfo("dig.chouti.com", "http", NULL, &aihead);
if(error) {
printf("error: %s\n", gai_strerror(error));
return error;
}
sleep(4);
printf("\n\n\n --- freeaddrinfo ---\n");
freeaddrinfo(aihead);
sleep(4);
return 0;
}
Code with malloc-hook
#include <sys/types.h>
#include <string.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
/* Prototypes for __malloc_hook, __free_hook */
#include <malloc.h>
/* Prototypes for our hooks. */
static void my_init_hook (void);
static void *my_malloc_hook (size_t, const void *);
static void my_free_hook (void*, const void *);
static void *(*old_malloc_hook) (size_t, const void *);
static void (*old_free_hook) (void*, const void *);
static void
my_init (void)
{
old_malloc_hook = __malloc_hook;
old_free_hook = __free_hook;
__malloc_hook = my_malloc_hook;
__free_hook = my_free_hook;
}
static void *
my_malloc_hook (size_t size, const void *caller)
{
void *result;
/* Restore all old hooks */
__malloc_hook = old_malloc_hook;
__free_hook = old_free_hook;
/* Call recursively */
result = malloc (size);
/* Save underlying hooks */
old_malloc_hook = __malloc_hook;
old_free_hook = __free_hook;
/* printf might call malloc, so protect it too. */
printf ("malloc (%u) returns %p\n", (unsigned int) size, result);
/* Restore our own hooks */
__malloc_hook = my_malloc_hook;
__free_hook = my_free_hook;
return result;
}
static void
my_free_hook (void *ptr, const void *caller)
{
/* Restore all old hooks */
__malloc_hook = old_malloc_hook;
__free_hook = old_free_hook;
/* Call recursively */
free (ptr);
/* Save underlying hooks */
old_malloc_hook = __malloc_hook;
old_free_hook = __free_hook;
/* printf might call free, so protect it too. */
printf ("freed pointer %p\n", ptr);
/* Restore our own hooks */
__malloc_hook = my_malloc_hook;
__free_hook = my_free_hook;
}
int main()
{
my_init();
struct addrinfo *aihead;
printf(" --- getaddrinfo ---\n");
int error = getaddrinfo("dig.chouti.com", "http", NULL, &aihead);
if(error) {
printf("error: %s\n", gai_strerror(error));
return error;
}
sleep(4);
printf("\n\n\n --- freeaddrinfo ---\n");
freeaddrinfo(aihead);
sleep(4);
return 0;
}
I find this in valgrind's output:
--13197-- Discarding syms at 0x55f9240-0x5600454 in /usr/lib64/libnss_files-2.17.so due to mu
--13197-- Discarding syms at 0x580b100-0x580e590 in /usr/lib64/libnss_dns-2.17.so due to munm
--13197-- Discarding syms at 0x5a13a40-0x5a22854 in /usr/lib64/libresolv-2.17.so due to munma
==13197== Invalid free() / delete / delete[] / realloc()
==13197== at 0x4C2AD17: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==13197== by 0x4F9963B: __libc_freeres (in /usr/lib64/libc-2.17.so)
==13197== by 0x4A246B4: _vgnU_freeres (in /usr/lib64/valgrind/vgpreload_core-amd64-linux.s
==13197== by 0x4E6DE2A: __run_exit_handlers (in /usr/lib64/libc-2.17.so)
==13197== by 0x4E6DEB4: exit (in /usr/lib64/libc-2.17.so)
==13197== by 0x4E56B1B: (below main) (in /usr/lib64/libc-2.17.so)
==13197== Address 0x51f03d0 is 0 bytes inside data symbol "noai6ai_cached"
It seems that libc-nss frees some memory at __run_exit_handlers() after exit().
So maybe valgrid keeps tracing memory after target process's exit(). While malloc-hook stops working after exit().
i am new to C++ and coding
how ever i attemped to make a mex file to use in matlab
the mex file has a problem for printing a parameter
i have sent the error picture
the code also is as below
`#include <windows.h>
#include <mex.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdint.h>
#include "./mavlink/v1.0/common/mavlink.h" //MAV_CMD_COMPONENT_ARM_DISARM is just defined
#include "C:\Users\SONY\Documents\Visual Studio 2010\Projects\code_test_2/inttypes.h"
#define STRICTfstat
#define WIN32_LEAN_AND_MEAN
#define CALL_TYPE_INIT 0
#define CALL_TYPE_CODE 1
#define CALL_TYPE_DECODE 2
#define CALL_TYPE_ARM 3
#define CALL_TYPE_DISARM 4
#ifndef MAV_CMD_COMPONENT_ARM_DISARM
#define MAV_CMD_COMPONENT_ARM_DISARM 400
#endif
unsigned char buf[4096]; // we put send and recive data in it enshaallah
int receive_chan = 0;
int system_id = 0;
int component_id = 0;
int APM_Sys_ID=0; // we use it instead of target sys ID
int APM_Comp_ID=0; // we use it instead of target component ID
mavlink_status_t status_copy;
mavlink_heartbeat_t system_heart_beat;
mavlink_message_t msg;
mavlink_attitude_t attitude; // it specifies the type of attitude. it says attitude is a data of type mavlink_attitude (hosein)
mavlink_rc_channels_raw_t rc_channels_raw;
void mexFunction(
int nlhs,
mxArray *plhs[],
int nrhs,
mxArray *prhs[]
)
{
double *CALL_TYPE = mxGetPr(prhs[0]);
if (*CALL_TYPE == CALL_TYPE_CODE){
uint16_t chan1_raw,chan2_raw,chan3_raw,chan4_raw,chan5_raw,chan6_raw,chan7_raw,chan8_raw;
printf("salam\n");
double *Actuators = mxGetPr(plhs[1]); // here we get the Actuators value which is prepared in matlab (it is sent from matlab to visula studio)
chan1_raw=1000*Actuators[0+8*0]+1000;
//chan2_raw=1000*Actuators[1+8*0]+1000;
//chan3_raw=1000*Actuators[2+8*0]+1000;
//chan4_raw=1000*Actuators[3+8*0]+1000;
//chan5_raw=1000*Actuators[4+8*0]+1000;
//chan6_raw=1000*Actuators[5+8*0]+1000;
//chan7_raw=1000*Actuators[6+8*0]+1000;
//chan8_raw=1000*Actuators[7+8*0]+1000;
/*mavlink_msg_rc_channels_override_pack(
system_id,
component_id,
&msg,//msg is out put and it is the way mavlink has determined and ali has no role on it
APM_Sys_ID,//we replaced target_system with APM_Sys_ID (this is the change we made in original code)
APM_Comp_ID,
chan1_raw,
chan2_raw,
chan3_raw,
chan4_raw,
chan5_raw,
chan6_raw,
chan7_raw,
chan8_raw);
*/
printf("% PRIu16\n",chan1_raw);
//printf("%i",chan2_raw);
//printf("%i",chan3_raw);
//printf("%i",chan4_raw);
//printf("%i",chan5_raw);
//printf("%i",chan6_raw);
}
}`
so please give me help for solving this problem if it is possible
I am trying to create a very simple topology containing a server and client connected via a router. The following code I got through a GUI. I am trying to run it but it throws me a long error I am new to ns-3, so kindly bear with me.
#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/core-module.h"
#include "ns3/common-module.h"
#include "ns3/global-route-manager.h"
#include "ns3/helper-module.h"
#include "ns3/bridge-module.h"
using namespace ns3;
int main(int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
/* Configuration. */
/* Build nodes. */
NodeContainer term_0;
term_0.Create (1);
NodeContainer term_1;
term_1.Create (1);
NodeContainer router_0;
router_0.Create (1);
/* Build link. */
CsmaHelper csma_hub_0;
csma_hub_0.SetChannelAttribute ("DataRate", DataRateValue (100000000));
csma_hub_0.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10000)));
CsmaHelper csma_hub_1;
csma_hub_1.SetChannelAttribute ("DataRate", DataRateValue (100000000));
csma_hub_1.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10000)));
/* Build link net device container. */
NodeContainer all_hub_0;
all_hub_0.Add (router_0);
all_hub_0.Add (term_0);
NetDeviceContainer ndc_hub_0 = csma_hub_0.Install (all_hub_0);
NodeContainer all_hub_1;
all_hub_1.Add (router_0);
all_hub_1.Add (term_1);
NetDeviceContainer ndc_hub_1 = csma_hub_1.Install (all_hub_1);
/* Install the IP stack. */
InternetStackHelper internetStackH;
internetStackH.Install (term_0);
internetStackH.Install (term_1);
internetStackH.Install (router_0);
/* IP assign. */
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.0.0.0", "255.255.255.0");
Ipv4InterfaceContainer iface_ndc_hub_0 = ipv4.Assign (ndc_hub_0);
ipv4.SetBase ("10.0.1.0", "255.255.255.0");
Ipv4InterfaceContainer iface_ndc_hub_1 = ipv4.Assign (ndc_hub_1);
/* Generate Route. */
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
/* Generate Application. */
uint16_t port_udpEcho_0 = 9;
UdpEchoServerHelper server_udpEcho_0 (port_udpEcho_0);
ApplicationContainer apps_udpEcho_0 = server_udpEcho_0.Install (term_1.Get(0));
apps_udpEcho_0.Start (Seconds (0.0));
apps_udpEcho_0.Stop (Seconds (2.0));
Time interPacketInterval_udpEcho_0 = Seconds (1.0);
UdpEchoClientHelper client_udpEcho_0 (iface_ndc_hub_1.GetAddress(1), 9);
client_udpEcho_0.SetAttribute ("MaxPackets", UintegerValue (1));
client_udpEcho_0.SetAttribute ("Interval", TimeValue (interPacketInterval_udpEcho_0));
client_udpEcho_0.SetAttribute ("PacketSize", UintegerValue (1024));
apps_udpEcho_0 = client_udpEcho_0.Install (term_0.Get (0));
apps_udpEcho_0.Start (Seconds (0.1));
apps_udpEcho_0.Stop (Seconds (2.0));
/* Simulation. */
/* Pcap output. */
/* Stop the simulation after x seconds. */
uint32_t stopTime = 3;
Simulator::Stop (Seconds (stopTime));
/* Start and clean simulation. */
Simulator::Run ();
Simulator::Destroy ();
}
If you are new, you should start your program by looking the examples already provided by ns-3. Like this: https://www.nsnam.org/doxygen/simple-routing-ping6_8cc_source.html. Looking the network topology, it is what you want.
Trying to run your code, I had to change a lot of headers to make it compile (maybe different versions, given the time - or your GUI is outdated). Remove yours and put these:
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/csma-helper.h"
And finally, you'd printed nothing, so I am not sure of what you were trying to do. As you are using, UdpEchoClientHelper and UdpEchoServerHelper, I would recommend to enable their logs. You can do this with these two lines:
/* Configuration. */
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
I am new too and I do not know what you are trying to do. So I will stop my answer here. Good luck.
I am trying to compile glib in ios, i have got an error in gio/tests/appinfo-test.h
#include <stdlib.h>
#include <gio/gio.h>
int
main (int argc, char *argv[])
{
const gchar *envvar;
gint pid_from_env;
envvar = g_getenv ("GIO_LAUNCHED_DESKTOP_FILE_PID");
g_assert (envvar != NULL);
pid_from_env = atoi (envvar);
g_assert_cmpint (pid_from_env, ==, getpid ());
envvar = g_getenv ("GIO_LAUNCHED_DESKTOP_FILE");
g_assert_cmpstr (envvar, ==, SRCDIR "/appinfo-test.desktop"); //got the error here that "Use of undefined identifier 'SRCDIR' "
return 0;
}
please help me out...Thank you
I can not figure out with given information how you tried to compile the sample code in your ios, but you can add
#define SRCDIR
before main().
The sample code seems to be glib/gio/tests/appinfo-test.c in the source repository. SRCDIR is defined as -DSRCDIR=\""$(srcdir)"\" in the Makefile.am.