ALL,
pcap_pkthdr pkthdr;
time_t nowtime = pkthdr->ts.tv_sec;
char tmbuf[64];
struct tm *nowtm = localtime( nowtime );
strftime( tmbuf, sizeof( tmbuf ), "%Y-%m-%d %H:%M:%S", nowtm );
Trying to compile this code using gcc with C++11, I am getting:
error: invalid conversion from 'time_t {aka long int}' to 'const time_t* {aka const long int*}' [-fpermissive]
struct tm *nowtm = localtime( nowtime );
^
What is wrong? Why am I getting an error?
localtime takes a pointer to time_t, you passed the time_t itself. Change it to:
struct tm *nowtm = localtime( &nowtime );
// ^ Takes address of nowtime
Related
I have a custom comparator and I pass in two const references of a custom struct to be compared, however, I get the following error:
'bool cmp::operator()(const LogObjects &, const LogObjects &)' cannot convert argument 2 from 'const_Ty' to 'const LogObjects &'.
I've tried adding and removing const, and references but it didn't work.
bool cmp::operator()(const LogObjects &a, const LogObjects &b) { // body }
struct LogObjects {
string category;
string message;
string timestamp;
long long int time;
int entry_id;
sort(master.begin(), master.end(), cmp());
auto it1 = lower_bound(master.begin(), master.end(), time, cmp());
auto it2 = upper_bound(master.begin(), master.end(), time, cmp());
};
(master is a vector of LogObjects and time is a long long int)
Just so the question can be closed, answering here as well.
time is a long long int
Is why you are getting the error.
lower_bound and upper_bound try to compare item in your vector( of type LogObject) with time (of type long long). Easiest way to fix would be to create LogObject timeObj and pass that to lower/upperBound. (If cmp depends on time only)
something like this:
LogObjects timeObject;
timeObject.time = time;
auto it1 = lower_bound(master.begin(), master.end(), timeObject, cmp());
auto it2 = upper_bound(master.begin(), master.end(), timeObject, cmp());
If I try to compile
printf("here %u\n", dest->q_head);
gcc complains with
error: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘ngx_uint_t {aka long unsigned int}’
fair enough..
But if I compile with
printf("here %lu\n", dest->q_head);
I get
error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘ngx_uint_t {aka unsigned int}’
Nothing else in the code changes.
ngx_uint_t is defined as...
typedef unsigned int ngx_uint_t;
dest->head is defined as...
ngx_uint_t q_head;
If I cast it to (unsigned int) it compiles and prints OK.
printf("here %u \n", (unsigned int)dest->q_head);
Any idea what is going on there?
the implementation of printf() does not know the term ngx_uint_t, the typedef does not change this. soprintf() simply does not know what is going on and throws errors
http://code.metager.de/source/xref/gnu/glibc/stdio-common/vfprintf.c from line 270 downwards
( http://code.metager.de/source/xref/gnu/glibc/stdio-common/printf.c printf() calls vfprintf() )
this is also the reason why it works when casted
According to microsoft visual studio 2013 (being built from QT creator, QT 5.4), this code is fine:
#include <string>
struct X {
X(std::string const &) {};
};
X wibble() { return ""; }
clang however says
test.cpp(53) : error: no viable conversion from 'const char [1]' to 'X'
X wibble() { return ""; }
test.cpp(49) : note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const char [1]' to 'const X &' for 1st argument
struct X {
test.cpp(49) : note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const char [1]' to 'X &&' for 1st argument
struct X {
test.cpp(50) : note: candidate constructor not viable: no known conversion from 'const char [1]' to 'const std::string &' (aka 'const basic_string<char, char_traits<char>, allocator<char> > &') for 1st argument
X(std::string const &) {};
It does the same thing with QString for what it's worth. Assuming clang is correct, why is it complaining?
It doesn't compile even in MinGW, because it is illegal. Because only one level of user-defined implicit conversion is legal. In your code you have 2 level conversion: to std::string and to X.
struct X {
X( std::string const &) {}
};
X wibble1() { return ""; } // 2 level: error
X wibble2() { return X(""); } // 1 level: ok
Even here you have same error:
void foobar(X x) {
}
int main()
{
foobar(X(""));// ok, 1 level
foobar ("f");
// error: could not convert '(const char*)"f"' from 'const char*' to 'X'
}
I would like to let the compiler choose registers automatically by parameter-izing my inline assembly in my C code, but I'm having some trouble. Can anyone tell me what is going wrong? If I use the code that I have commented out (forcing the affiliation with %xmm0), it will compile and get the expected result. But if I leave it commented out as written here, I get the compiler error:
/tmp/ccJxmSbm.s: Assembler messages:
/tmp/ccJxmSbm.s:81: Error: the first operand of `blendvpd' must be `%xmm0'
Also, if I do nothing other than remove the printf statement, the code block compiles successfully too. So it has something to do with moving parameters around to prepare for the printf call. I have explicitly put in the "Yz" constraint which is supposed to force the use of %xmm0, but it looks like it is not being honored.
Here is the code in question:
#include <stdio.h>
const unsigned long long myConst[2] = {0x0000000000000000,0xffffffffffffffff};
const unsigned long long myConst2[2] = {0x0000000000000000,0x1111111111111111};
const unsigned long long myConst3[2] = {0x0123456789abcdef,0x0000000000000000};
#define ASSIGN_CONST128( val, const ) \
val = *((__uint128_t *)const);
int main( void )
{
register __uint128_t regVal1 /* asm("%xmm0") */ ;
register __uint128_t regVal2;
register __uint128_t regVal3;
ASSIGN_CONST128( regVal1, myConst );
ASSIGN_CONST128( regVal2, myConst2 );
ASSIGN_CONST128( regVal3, myConst3 );
asm( "blendvpd %[mask], %[val1], %[val2]" :
[val2] "+x" (regVal3) :
[mask] "Yz" (regVal1),
[val1] "x" (regVal2) );
printf( "REGVAL1: %016llx%016llx (original=%016llx%016llx)\n"
"REGVAL2: %016llx%016llx (original=%016llx%016llx)\n"
"REGVAL3: %016llx%016llx (original=%016llx%016llx)\n",
(unsigned long long)(regVal1>>64), (unsigned long long)regVal1,
myConst[1], myConst[0],
(unsigned long long)(regVal2>>64), (unsigned long long)regVal2,
myConst2[1], myConst2[0],
(unsigned long long)(regVal3>>64), (unsigned long long)regVal3,
myConst3[1], myConst3[0] );
// Expected result:
// REGVAL1: ffffffffffffffff0000000000000000 (original=ffffffffffffffff0000000000000000)
// REGVAL2: 11111111111111110000000000000000 (original=11111111111111110000000000000000)
// REGVAL3: 11111111111111110123456789abcdef (original=00000000000000000123456789abcdef)
}
I appreciate any thoughts.
Why not just use the relevant intrinsic?
regVal3 = _mm_blendv_pd (regVal1, regVal2, regVal3);
As others have noted, regVal1, regVal2 and regVal3 should all be declared as __m128d.
I have problem to pass request variable in my gsoap client app. The error is Segmentation Fault (core dump).
This is my header file:
class _ns1__NewTransactionDataRequest;
class _ns1__NewTransactionDataResponse;
class _ns1__GetTransactionResultRequest;
class _ns1__GetTransactionResultResponse;
class _ns1__NewTransactionDataRequest
{
public:
char* UserID 1;
char* UserPwd 1;
char* TransID 1;
char* TransDate 1;
char* A_NO 1;
char* B_NO 1;
char* Denom 1;
char* TransType 1;
struct soap *soap ;
};
class _ns1__NewTransactionDataResponse
{ public:
char* TransID 1;
char* ResultCode 1;
char* ResultDesc 1;
struct soap *soap ;
};
class _ns1__GetTransactionResultRequest
{
public:
char* UserID 1;
char* UserPwd 1;
char* TransID 1;
char* TransDate 1;
char* A_NO 1;
char* B_NO 1;
char* Status 1;
char* Remark 1;
struct soap *soap ;
};
class _ns1__GetTransactionResultResponse
{
public:
char* TransID 1;
char* ResultCode 1;
char* ResultDesc 1;
struct soap *soap ;
};
int __ns1__NewTransactionData(_ns1__NewTransactionDataRequest* ns1__NewTransactionDataRequest, _ns1__NewTransactionDataResponse* ns1__NewTransactionDataResponse
);
int __ns1__GetTransactionResult(_ns1__GetTransactionResultRequest*ns1__GetTransactionResultRequest,_ns1__GetTransactionResultResponse* ns1__GetTransactionResultResponse
);
This is the client app that I try to compile:
int main(int argc, char **argv)
{
struct soap soap;
_ns1__GetTransactionResultRequest *ns1__GetTransactionResultRequest;
_ns1__GetTransactionResultResponse *ns1__GetTransactionResultResponse;
_ns1__NewTransactionDataRequest *ns1__NewTransactionDataRequest;
_ns1__NewTransactionDataResponse *ns1__NewTransactionDataResponse;
(*ns1__GetTransactionResultRequest).UserID = "myuserid"; //<--fail at this line
(*ns1__GetTransactionResultRequest).UserPwd = "userpwd";
(*ns1__GetTransactionResultRequest).TransID = "amwani";
(*ns1__GetTransactionResultRequest).TransDate = "2013-09-09 01:01:01";
(*ns1__GetTransactionResultRequest).A_NO = "mynumber";
(*ns1__GetTransactionResultRequest).B_NO = "yournumber";
(*ns1__GetTransactionResultRequest).Status = "success";
(*ns1__GetTransactionResultRequest).Remark = "done";
printf("Content-type: text/html\r\n\r\n<html><h1>Magic Square of Rank</h1><pre>\n");
if (soap_call___ns1__GetTransactionResult(&soap, server, NULL, ns1__GetTransactionResultRequest, ns1__GetTransactionResultResponse))
{
soap_print_fault(&soap, stderr);
soap_print_fault_location(&soap, stderr);
}
else
{
printf("%s", (*ns1__GetTransactionResultRequest).TransID);
}
printf("</pre></html>\n");
soap_destroy(&soap);
soap_end(&soap);
soap_done(&soap);
}
I did not get any error during compilaton, but few warnings:
xpulsaclient.cpp: In function ‘int main(int, char**)’:
xpulsaclient.cpp:46: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:47: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:48: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:49: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:50: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:51: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:52: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:53: warning: deprecated conversion from string constant to ‘char*’
xpulsaclient.cpp:42: warning: unused variable ‘ns1__NewTransactionDataRequest’
xpulsaclient.cpp:43: warning: unused variable ‘ns1__NewTransactionDataResponse’
xpulsaclient.cpp:46: warning: ‘ns1__GetTransactionResultRequest’ is used uninitialized in this function
xpulsaclient.cpp:57: warning: ‘ns1__GetTransactionResultResponse’ may be used uninitialized in this function
Maybe the way I initialize variable in class ns1_GetTransactionResultRequest is not correct that caused the segmentation fault?. Can anyone help me? I have been stuck at this point for 2 days....Thanks!
You're right - you're not initializing ns1__GetTransactionResultRequest (or any of the other pointers). The variables you've declared are pointers, but they're never assigned to a new object. You can either instantiate objects, or declare the variables on the stack instead.
I've posted a simple gSOAP client app in another response. It includes assignment to a gSOAP request object property, which should help you out.
Example: making a web services query using gSoap with query arguments