# 64bit c++ app and 32kdb sever

**URL:** <https://forum.kx.com/t/64bit-c-app-and-32kdb-sever/10689>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [December 27, 2015, 10:52pm UTC](https://forum.kx.com/t/64bit-c-app-and-32kdb-sever/10689 "2015-12-27T22:52:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oranjsr](https://avatars.discourse-cdn.com/v4/letter/o/3d9bf3/32.png) [@oranjsr](https://forum.kx.com/u/oranjsr)\
**Post date:** [December 27, 2015, 10:52pm UTC](https://forum.kx.com/t/64bit-c-app-and-32kdb-sever/10689/1 "2015-12-27T22:52:00Z")

</div>

Hi all,

Referencing “[http://code.kx.com/wiki/Cookbook/InterfacingWithC](http://code.kx.com/wiki/Cookbook/InterfacingWithC)”, I was able to create the following table via a 64bit c++ app;

stime &nbsp; &nbsp; &nbsp; &nbsp;rtime &nbsp; &nbsp; &nbsp; &nbsp;sym bidprice bidsize askprice asksize&nbsp;

-----------------------------------------------------------------------------..

06:14:25.847 06:14:25.882 ES &nbsp;205175 &nbsp; 69 &nbsp; &nbsp; &nbsp;205200 &nbsp; 18

06:14:32.615 06:14:32.655 ES &nbsp;205175 &nbsp; 70 &nbsp; &nbsp; &nbsp;205200 &nbsp; 18

06:14:33.265 06:14:33.305 ES &nbsp;205175 &nbsp; 71 &nbsp; &nbsp; &nbsp;205200 &nbsp; 14

06:14:33.965 06:14:34.005 ES &nbsp;205175 &nbsp; 69 &nbsp; &nbsp; &nbsp;205200 &nbsp; 19

06:14:38.015 06:14:38.055 ES &nbsp;205175 &nbsp; 69 &nbsp; &nbsp; &nbsp;205200 &nbsp; 20

06:14:39.215 06:14:39.255 ES &nbsp;205175 &nbsp; 69 &nbsp; &nbsp; &nbsp;205200 &nbsp; 21

However, when I try to access the data and manipulate it via c++ the following code does not work. &nbsp;Is the code in error or is using a 64bit app the 32bit app not possible?

#include\<cstdio\>

#include\<cstdlib\>

#include"k.h"

// obtain k.h from [http://kx.com/q/c/c/k.h](http://kx.com/q/c/c/k.h)

// linux:

// &nbsp;compile with gcc -m64 -DKXVER=3 csv.c c.o

// &nbsp;obtain c.o from [http://kx.com/q/l64/c.o](http://kx.com/q/l64/c.o) for linux

// windows:

// &nbsp;start the x86 or 64 bit version of build environment, then: cl -DKXVER=3 /MD csv.c c.obj ws2\_32.lib

// &nbsp;obtain c.obj from [http://kx.com/q/w32/](http://kx.com/q/w32/) or w64/

int main(int argc,char\*argv)

{

int handle = khpu((S) “localhost”, 5000, (S) “myusername:mypassword”);

if (handle \< 0)

{

printf(“Cannot connect\n”);

return 1;

}

else if (!handle)

{

printf(“Wrong credentials\n”);

return 1;

}

/\*

&nbsp; Get a keyed table by executing a query.

\*/

K x = k(handle, “select from quote”, (K)0);

/\*

&nbsp; Convert the result to a simple table.

&nbsp; NB. x is no longer valid and has been deallocated.

\*/

K y=ktd(x);

/\*

&nbsp; Note that if the ktd conversion fails for any reason,

&nbsp; it returns 0 and x is not freed.

&nbsp; since 2011-01-27, ktd always decrements ref count of input.

\*/

if (0 == y)

&nbsp; &nbsp;(void) puts (“x is still a keyed table because the conversion failed.”);

else

&nbsp; &nbsp;(void) puts (“y is a simple table and x has been deallocated.”);

&nbsp; &nbsp; K columnNames=kK(y-\>k)[0];

&nbsp; &nbsp; K columnData=kK(y-\>k)[1];

&nbsp; &nbsp; **int nCols=columnNames-\>n; \<\<\<\<\< cause seg fault**

&nbsp; &nbsp; int nRows=kK(columnData)[0]-\>n;

&nbsp; &nbsp; for(int row=0;row\<nRows;row++)

&nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; if(0==row)

&nbsp; &nbsp; &nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(int col=0;col\<nCols;col++)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(col\>0)printf(“,”);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(“%s”,kS(columnNames)[col]);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(“\n”);

&nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; for(int col=0;col\<nCols;col++)

&nbsp; &nbsp; &nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; K obj=kK(columnData)[col];

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(col\>0)printf(“,”);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch(obj-\>t)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case(0):{ // handle a list of char vectors

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; K x=kK(obj)[row];

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(10==x-\>t){int i;for(i=0;i\<xn;i++)printf(“%c”,kG(x)[i]);}

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else printf(“type %d not supported by this client”,obj-\>t);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case(1):{printf(“%d”,kG(obj)[row]);}break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case(4):{printf(“%d”,kG(obj)[row]);}break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case(5):{printf(“%d”,kH(obj)[row]);}break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case(6):{printf(“%d”,kI(obj)[row]);}break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case(7):{printf(“%lld”,kJ(obj)[row]);}break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case(8):{printf(“%f”,kE(obj)[row]);}break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case(9):{printf(“%f”,kF(obj)[row]);}break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case(11):{printf(“%s”,kS(obj)[row]);}break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:{printf(“type %d not supported by this client”,obj-\>t);}break;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; printf(“\n”);

&nbsp; &nbsp; }

&nbsp; &nbsp; kclose(handle);

&nbsp; &nbsp; return 0;

}

&nbsp;

Thanks,

Oran

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [December 28, 2015, 8:16am UTC](https://forum.kx.com/t/64bit-c-app-and-32kdb-sever/10689/2 "2015-12-28T08:16:00Z")

</div>

Hi Oran,

the kdb+ ipc format is the same regardless of whether the sender/receiver is 32 or 64bit, so 32bit apps can communicate with 64bit apps.

Which OS/platform are you building for?

Are you using the correct c.o? e.g.  
32bit for linux - kx.com/q/l32/c.o

64bit for linux - kx.com/q/l64/c.o

Did you define KXVER to be 3?

What is your compile cmd line? e.g. gcc example.c …

Which of these did it print?

if (0 == y)

&nbsp; &nbsp;(void) puts (“x is still a keyed table because the conversion failed.”);

else

&nbsp; &nbsp;(void) puts (“y is a simple table and x has been deallocated.”);

For sanity checks you might also like to check the return value as in the example

&nbsp; if(!result)  
&nbsp; &nbsp; &nbsp; &nbsp; printf(“Network Error\n”),perror(“Network”),exit(1);  
&nbsp; &nbsp; kclose(handle);  
&nbsp; &nbsp; if(result-\>t==-128)  
&nbsp; &nbsp; &nbsp; &nbsp; printf(“Server Error %s\n”,result-\>s),r0(result),exit(1);  
&nbsp; &nbsp; if(result-\>t!=99&&result-\>t!=98) // accept table or dict  
&nbsp; &nbsp; &nbsp; &nbsp; printf(“type %d\n”,result-\>t),r0(result),exit(1);

hth,  
Charlie

---

<div class="post-metadata">

**Author:** ![oranjsr](https://avatars.discourse-cdn.com/v4/letter/o/3d9bf3/32.png) [@oranjsr](https://forum.kx.com/u/oranjsr)\
**Post date:** [December 28, 2015, 10:09am UTC](https://forum.kx.com/t/64bit-c-app-and-32kdb-sever/10689/3 "2015-12-28T10:09:00Z")

</div>

Hi Charlie,

I&nbsp;defined KXVER to be 3 and it worked.

Thanks,

Oran

---

<div class="post-metadata">

**Author:** ![oranjsr](https://avatars.discourse-cdn.com/v4/letter/o/3d9bf3/32.png) [@oranjsr](https://forum.kx.com/u/oranjsr)\
**Post date:** [December 28, 2015, 10:24am UTC](https://forum.kx.com/t/64bit-c-app-and-32kdb-sever/10689/4 "2015-12-28T10:24:00Z")

</div>

Hi Charlie,

Anyway around this?

type 19 not supported by this client,type 19 not supported by this client

Thanks,

Oran

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [December 28, 2015, 12:02pm UTC](https://forum.kx.com/t/64bit-c-app-and-32kdb-sever/10689/5 "2015-12-28T12:02:00Z")

</div>

Hi Oran,

type 19 is the time type. e.g.  
q)type 10:00:00.000  
-19h  
q)type enlist 10:00:00.000  
19h

I’ll flesh out csv.c later but in the meantime you can derive the remaining cases from http://www.aquaq.co.uk/wp-content/uploads/2015/01/AquaQ-Analytics-Transferring-Data-between-kdb±and-C-V1.0.pdf

thanks,

Charlie

---

<div class="post-metadata">

**Author:** ![oranjsr](https://avatars.discourse-cdn.com/v4/letter/o/3d9bf3/32.png) [@oranjsr](https://forum.kx.com/u/oranjsr)\
**Post date:** [December 28, 2015, 12:48pm UTC](https://forum.kx.com/t/64bit-c-app-and-32kdb-sever/10689/6 "2015-12-28T12:48:00Z")

</div>

Hi Charlie,

Thanks.

Oran
