What programing language is this? [closed] - programming-languages

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Someone know what kind of language used below:
String^ fileName = "C:\\Test1.txt";
array<Byte>^ Array = gcnew array<Byte>(512);
try
{
FileStream^ fs = File::OpenRead(fileName);
fs->Read(Array, 0, 512);fs->Close();
}
catch (...)
{
MessageBox::Show("Disk error");
Application::Exit();
}
and another example of that language:
int RotateLeft3 (int number)
{
if ( ( number & 0x20000000 ) == 0x20000000 )
{
number <<= 3;number |= 1;
}
else
number <<= 3;
return number;
}

Its C++ in .NET. You can tell by the use of ^ as pointer instead of *

This is C++/CLI, in other words the C++ variant that runs on top of the .Net CLR.
On no account should this be confused with native C++.

It looks like managed c++ from Microsoft.

Related

Converting NodeJS byte buffer [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm trying to figure out how to convert NodeJS code like this:
const buffer = new Buffer(24);
offset = buffer.writeUInt32BE(this.a, offset);
offset = buffer.writeUInt32BE(this.b, offset);
offset = buffer.writeUInt8(this.c, offset);
offset = buffer.writeUInt16BE(d, e); 1 : 0, offset);
buffer.writeInt8(this.f, offset);
to Go.
I figured I could use
buffer := make([]byte, 24)
buffer[0] = a
buffer[2] = b
but this is not working
is there a recommended way to do something like this with Go?
You should use binary.ByteOrder.
So in your case, using Big Endian, something like :
package main
import (
"encoding/binary"
)
func main() {
buffer := make([]byte, 24)
// Uint32
binary.BigEndian.PutUint32(buffer, 1)
binary.BigEndian.PutUint32(buffer[4:], 2)
// Uint8
buffer[8] = 3
// Uint16
binary.BigEndian.PutUint16(buffer[9:], 4)
// Uint8
buffer[13] = 5
}

Wrong u128 multiplication in Rust? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Before I open bug, I want to check what is going on here.
I'm porting this C-code here to Rust:
unsigned __int128 r = (unsigned __int128)a * (unsigned __int128)b;
easy enough (I thought):
let r = (a as u128) * (b as u128);
Now with this input parameters I get a different multiplication result in C and Rust:
(0x56eaa5f5f650a9e3 as u128) * (0xa0cf24341e75bda9 as u128)
The results are different in Rust and C:
Rust: 0x3698fbc09d2c5b15e8889b1b676bbddb
C: 0x3698fbc0f417010bded944fe676bbddb
^^^^^^^^^^^^^^^^
I cross-checked the result, and got the same result as the C code.
Am I missing something?
=== context information added:
It is this function from xmr-stak (https://github.com/fireice-uk/xmr-stak) thas is behaving differently:
static inline uint64_t _umul128(uint64_t a, uint64_t b, uint64_t* hi)
{
unsigned __int128 r = (unsigned __int128)a * (unsigned __int128)b;
*hi = r >> 64;
return (uint64_t)r;
}
Regardless if the C implementation is wrong, I have to recreate the exact computation in Rust, because this is needed for a hash computation.
I looks like you must have a made a typo in either language:
>>> hex(0x3698fbc09d2c5b15e8889b1b676bbddb//0x56eaa5f5f650a9e3)
'0xa0cf24341e75bda9' # what your Rust code uses
>>> hex(0x3698fbc0f417010bded944fe676bbddb//0x56eaa5f5f650a9e3)
'0xa0cf24351e75bda9' # what your online calculator uses
^
Classical case of off-by-0x100000000 error :)

Easy tool to convert data to different format [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm studying statistics and programming on my own. What kind of C or Python program will solve the following problem in Linux?
I have a text (maybe CSV) file of the form
pcb138 pcb180 pcb52 pcb118 pcb
1,46 ,738 ,532 ,72 19,9959
,64 ,664 ,03 ,236 6,0996
3,29 1,15 ,134 1,54 24,9655
3,94 1,33 ,466 1,94 37,4436
...
32,3 31,5 1,8 8,49 318,7461
Now I would like to convert those to another format that another program understands. Namely, a text file of the form
pcb138=[1.46,0.64,3.94,...,32.3]
pcb180=[0.738,0.664, 1.15,1.33,...,31.5]
pbc52=[0.532, 0.03, 0.134, 0.466, ...,1.8]
pbc118=[0.72, 0.236, 0.154, 1.94, ...,8.49]
pbc=[19.9959, 6.0996, 24.9655, 37.4436, ...,318.7461]
Write a C program using a 2 dimensional array and strtok() to do the parsing
http://www.cplusplus.com/reference/cstring/strtok/
/* strtok example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}

Software interrupt on network traffic [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
On my computer there is 3G, Wifi and LAN port. I would like to build a linux software to show green color if there is network traffic and red color for no network traffic.
TCPDUMP could provide the real time statistics but it would generate high CPU load. Therefore I wonder if I could get the real time statistics via software interrupt? Whenever there is network traffic a software interrupt will be generated.
Thanks in advance
I don't know whether you'd call this a software interrupt, but you could consult the following example. (The third argument to poll() is the time in milliseconds after which the network is considered inactive.)
/* compile with -lpcap */
/* run as root */
#include <stdio.h>
#include <sys/poll.h>
#include <pcap.h>
int main(int argc, char *argv[])
{
int color = 0;
struct pollfd ufd;
struct pcap_pkthdr h;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *p = pcap_open_live(NULL, 0, 0, 0, errbuf);
if (!p) return puts(errbuf), 1;
ufd.fd = pcap_fileno(p);
ufd.events = POLLIN;
for (; ; )
switch (poll(&ufd, 1, 100))
{
case -1: perror("poll"); return 1;
case 0: if (color) color = 0, puts("red"); break;
default: if (!color) color = 1, puts("green");
pcap_next(p, &h);
}
}

Loading a Directory into a Tree Control [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can I load files and folders into tree control using vc++.
Is any functions available ?
If it is a windows based system you can use the Win32 API FindFirstFile, FindNextFile and FindClose functions. One small example.
If it is an MFC application you can use CFileFind class. Checkout this example from MSDN.
#include <afxwin.h>
#include <iostream>
using namespace std;
void Recurse(LPCTSTR pstr)
{
CFileFind finder;
// build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("\\*.*");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
// skip . and .. files; otherwise, we'd
// recur infinitely!
if (finder.IsDots())
continue;
// if it's a directory, recursively search it
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
cout << (LPCTSTR) str << endl;
Recurse(str);
}
}
finder.Close();
}

Resources