question
stringlengths 24
425
| answer
stringlengths 5
405
|
---|---|
I was wondering if there is a way to get the installed memory type in Windows? I mean is there an API or any other way to query that on a PC there is DDR2 or DDR3 or SDRAM installed?
Thanks!
| CPU-IDis able to do it, so it's definitely possible. They have aSDKavailable, but it'sexpensive.
QueryingWin32_PhysicalMemoryusing WMI may also help and is possible usingC/C++.
|
I am trying to find an integer type length in C. Does anyone have a quick algorithm to check the length of it?
Thanks.
| Do you mean this?
```
sizeof (int)
```
If you want it measured in bits, try
```
#include <limits.h>
(CHAR_BIT * sizeof (int))
```
|
I want to create a processBfrom processA. However, I don't wantBto be the child ofA, which will be the case if I simply usefork. How can I achieve that? In other words I want processBto keep on executing even if processAis killed.
| You can use the setsid() function.
Alternatively, as you have tagged your question "linux", maybe you want to use daemon() instead of fork() + setsid().
|
Is there any possiblty to swap three numbers in a single statement
Eg :
a = 10b = 20c = 30
I want values to be changed as per the following list
```
a = 20
b = 30
c = 10
```
Can these values be transferred in a single line?
| ```
$ python
>>> a, b, c = 10, 20, 30
>>> print a, b, c
10 20 30
>>> a, b, c = b, c, a
>>> print a, b, c
20 30 10
```
|
Is there any possiblty to swap three numbers in a single statement
Eg :
a = 10b = 20c = 30
I want values to be changed as per the following list
```
a = 20
b = 30
c = 10
```
Can these values be transferred in a single line?
| ```
$ python
>>> a, b, c = 10, 20, 30
>>> print a, b, c
10 20 30
>>> a, b, c = b, c, a
>>> print a, b, c
20 30 10
```
|
What is the best way to represent a C array in Erlang? I plan on passing a C array to Erlang using NIF. The array is composed of bytes and I'll need to modify some of the bytes as the program runs. Any help is appreciated.
| If function in NIF not reallocate array than you can represent you array as a tuple with two elements - raw pointer and elements count.
|
When I disassembled my C code, I saw the following. What does this code do exactly? Does it have something to do with floating points?
```
movsd (%rdx,%rax,8),%xmm0
mulsd %xmm0,%xmm0
movsd %xmm0,0x30(%rsp)
```
| it squares a number:
```
xmm0=*(rdx*8+rax);
xmm0*=xmm0;
rsp[0x30]=xmmm0;
```
xmm0 is a floating point register.
|
How can you know ifpopen()succeeded/done running the shell or failed?
| popen return value:
Upon successful completion, popen() shall return a pointer to an open
stream that can be used to read or write to the pipe. Otherwise, it
shall return a null pointer and may set errno to indicate the error.
```
fp = popen("ls *", "r");
if (fp == NULL)
/* Handle error */;
```
|
How to process (in read-only fashion) a big binary file inC/C++onLinuxas fast as possible? Viareadormmap? What buffer size? (No boost or anything.)
| mmap is faster and optimal for read only applications. See answer here:
https://stackoverflow.com/a/258097/1094175
|
How can you know ifpopen()succeeded/done running the shell or failed?
| popen return value:
Upon successful completion, popen() shall return a pointer to an open
stream that can be used to read or write to the pipe. Otherwise, it
shall return a null pointer and may set errno to indicate the error.
```
fp = popen("ls *", "r");
if (fp == NULL)
/* Handle error */;
```
|
How to process (in read-only fashion) a big binary file inC/C++onLinuxas fast as possible? Viareadormmap? What buffer size? (No boost or anything.)
| mmap is faster and optimal for read only applications. See answer here:
https://stackoverflow.com/a/258097/1094175
|
Can someone explain please how to set a filter usingstruct bpf_programmemberstruct bpf_insn? All documentation and tutorials are welcome, for example what would be the struct bpf_insn if i want to filter for example dhcp, dns or ...?
Thanks for your help.
| This tutorial uses struct bpf_program to create a filter program, not sure if that helps much but it's worth a look. (scroll down to the tcp bit).
http://www.enderunix.org/docs/en/rawipspoof/
|
I'm learning C . I want to list an array's values.
In PHP :
```
$arr = array("laguna", "megane", "clio");
foreach($arr as $no => $name)
{
echo $no." ) ".$name;
}
/*
Output :
0) Laguna
1) Megane
2) Clio
*/
```
How can i do it in C?
| In C
```
char* arr[] = {"laguna","megane","clio",NULL};
for( int i = 0; arr[i]; i++)
{
printf("%d) %s\n",i,arr[i]);
}
```
|
What is mnemonic for "W" i.e. what does "W" mean in the following macros:
```
int WIFEXITED (int status)
int WEXITSTATUS (int status)
int WIFSIGNALED (int status)
int WTERMSIG (int status)
int WCOREDUMP (int status)
int WIFSTOPPED (int status)
int WSTOPSIG (int status)
```
Also seeProcess Status Completion.
| It is simply related toW-aiting functions like thewaitpidsyscall.
|
Is there an efficient way of finding thetask_structfor a specified PID, without iterating through thetask_structlist?
| What's wrong with using one of the following?
```
extern struct task_struct *find_task_by_vpid(pid_t nr);
extern struct task_struct *find_task_by_pid_ns(pid_t nr,
struct pid_namespace *ns);
```
|
Is there an efficient way of finding thetask_structfor a specified PID, without iterating through thetask_structlist?
| What's wrong with using one of the following?
```
extern struct task_struct *find_task_by_vpid(pid_t nr);
extern struct task_struct *find_task_by_pid_ns(pid_t nr,
struct pid_namespace *ns);
```
|
Is it possible to write a string on aIplImagewith Opencv 2.1 in C/C++?
Thank you.
| Yes,cvPutText():
```
CvFont font;
double hScale=1.0;
double vScale=1.0;
int lineWidth=1;
cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX|CV_FONT_ITALIC, hScale,vScale,0,lineWidth);
cvPutText (img,"My comment",cvPoint(200,400), &font, cvScalar(255,255,0));
```
|
This question already has answers here:Closed11 years ago.
Possible Duplicate:Meaning of U suffix
I'm going through code that has a bunch of defines that look like:
#define HEX_NUMBER (0x000000FFu)
What is the trailing u? I've tried compiling with and without it and I don't see any difference.
| Appendinguto any integral constant makes the compiler interpret it as unsigned.
|
Using x86 platform , I want to start my application named myapp through this method:execl("./myapp","");It's OK! But failed when I'm using ARM platform + embedded linux. Why ? Any help will be appreciated. Thanks in advance.
| Your invocation is wrong:execl()'s argument list MUST be terminated withNULL.
The fact that it works at all on x86 is a miracle ;)
|
I know that I am asking an incredibly low level question, but I am unfamiliar with C and am trying to convert an expression to Objective-C. What does this mean?
```
double (*x)[2]
```
Thanks.
| With a semicolon at the end, it declares and defines a pointer (namedx) to a array of 2 doubles. If it's a function (or method) argument, its type is the same: a pointer to an array of 2 doubles.
|
The standard predefined macro__FILE__available in C shows the full path to the file. Is there any way to shorten the path and get just the filename? I mean instead of
```
/full/path/to/file.c
```
I see
```
to/file.c
```
or
```
file.c
```
| Try
```
#include <string.h>
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
```
For Windows use '\\' instead of '/'.
|
How to swap the nibble bit positions of a number?
For example: 534, convert it into binary, the rightmost 4 bits has to be interchanged with the leftmost 4 bits and then make a new number with that.
Anyone know how to do this?
| Sean Anderson's bit twiddling guidehas the following:
```
// swap nibbles ...
v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4);
```
under the entry forReverse an N-bit quantity in parallel in 5 * lg(N) operations.
|
The standard predefined macro__FILE__available in C shows the full path to the file. Is there any way to shorten the path and get just the filename? I mean instead of
```
/full/path/to/file.c
```
I see
```
to/file.c
```
or
```
file.c
```
| Try
```
#include <string.h>
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
```
For Windows use '\\' instead of '/'.
|
How to swap the nibble bit positions of a number?
For example: 534, convert it into binary, the rightmost 4 bits has to be interchanged with the leftmost 4 bits and then make a new number with that.
Anyone know how to do this?
| Sean Anderson's bit twiddling guidehas the following:
```
// swap nibbles ...
v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4);
```
under the entry forReverse an N-bit quantity in parallel in 5 * lg(N) operations.
|
Iwant to transfer a file to a particular directory on FTP server . If it does not exists on the server then it has to be created there and file will be placed .
Platform : Linux , gcc compiler
Thanks .
| Start with theftpuploadexample inlibcurl.
|
I got a pcap file with voip conversation, how i can separate RTP packets from the other packets?
I can obtain sip packets, but I can't differenciate the RTP packets from the rest.
| Search for RTP headers as defined inRFC3550within your file. Or better use pcap-filter, for instance withthiswiki (look for "Q: What is a good filter for just capturing SIP and RTP packets?").
|
Iwant to transfer a file to a particular directory on FTP server . If it does not exists on the server then it has to be created there and file will be placed .
Platform : Linux , gcc compiler
Thanks .
| Start with theftpuploadexample inlibcurl.
|
I was just wondering whether it was possible to do something like this:
```
char yn;
scanf("%79/6ec",yn);
```
so yn can only become either y (0x79) or n (0x6e)
| No , but you could use scanf to read a char
```
scanf("%c" , &yn );
```
after that you have to check whether it is y/n or illegal input.
```
if ( yn == 'y' ) {
...
}
```
|
How do I format a time_t structure to something like this year-month-day h:m:s,
I have already tried using ctime:
```
time_t t = time((time_t*) NULL);
char *t_format = ctime(&t);
```
but it doesn't give me the desired results
example :
2011-11-10 10:25:03. What I need is a string containing the result so I can write it to a file. Thanks
| Usestrftimefromtime.hlike so:
```
char tc[256];
strftime(tc, 256, "%Y-%m-%d %H:%M:%S", tm);
```
|
I have C program ( program.c ) that calls a shell script ( command.sh ).
command.sh returns an output (a password), i need to get this output in my program.c.
usingsystem(command);, i can't get hold of the output.
is there any other way in C to solve my problem?
| Not in pure C. You want POSIX. Specificallypopenfunction.
The specification has a nice example, that you can just copy 1:1http://pubs.opengroup.org/onlinepubs/009604499/functions/popen.html
|
Is there a tool toautomaticallygenerate Fortanbindingsfrom C library header, using intrinsiciso_c_bindingsmodule from Fortran 2003 standard?
I am not interested intranslatingC to Fortran, but only generating bindings.
| An automatic tool was used to get thegtk-fortranbindings. It is a Python scriptcfwrapper.py. You might be able to adapt it to for your needs, although for my small problems I finally chose to make the bindings by hand.
|
I need to create a string on the heap, I was wondering if there is something similar already included in the standard libraries, or do I have to implement it myself (using malloc())?
| You could usemalloc(),calloc()orstrdup()(the latter is POSIX, not standard C).
It is not totally clear what you mean by "implement it myself (usingmalloc())" -- what exactly is there to implement?
|
I have a string,
```
char* str = "HELLO"
```
If I wanted to get just theEfrom that how would I do that?
| ```
char* str = "HELLO";
char c = str[1];
```
Keep in mind that arrays and strings in C begin indexing at 0 rather than 1, so "H" isstr[0], "E" isstr[1], the first "L" isstr[2]and so on.
|
I have two filesPosit.candHeadPose.cpp
Posit.ccompiled toPositnew
My question is
How to call already compiled Positnew like thissystem("Positnew");from HeadPose.cpp
| Just use c keywordexternto declare the function then the linker will make sure that it can be linked either dynamically or statically.
extern void Positnew()
|
I want to set up an environment on my PC (Win7x64) that I will be able to combine these projects and compile them into one executable:
FFmpegAMV codec tools
For this I need an environment that can compile/debug both the above projects (creating a Windows compatible exe).
Any ideas?
| http://ffmpeg.arrozcru.org/wiki/index.php?title=Main_PageNetBeans can handle MinGW. (Might be other IDEs, but I've used MinGW under NetBeans so I know it can.)
|
I want to set up an environment on my PC (Win7x64) that I will be able to combine these projects and compile them into one executable:
FFmpegAMV codec tools
For this I need an environment that can compile/debug both the above projects (creating a Windows compatible exe).
Any ideas?
| http://ffmpeg.arrozcru.org/wiki/index.php?title=Main_PageNetBeans can handle MinGW. (Might be other IDEs, but I've used MinGW under NetBeans so I know it can.)
|
I am new to the C language and pointers and I am confused by this function declaration:
```
void someFunction(int (*)(const void *, const void *));
```
Can anyone explain in layman's terms what this does and how it works?
| It's the prototype of a function that takes:
a pointer to a function that takes aconst void*and aconst void*as arguments and returns anint
as an argument, and returnsvoid.
|
Are there some libraries with C API to draw pictures? Just like the librarymatplotlibin python. I will use it to draw lines, dots, circles and I hope it has detailed documentation and opensource. My platform is gentoo.
| The most comprehensive one is probablyImageMagick. They suggest using theMagickWandAPI.
Other options arecairo, with a image buffer output device, or maybelibgd.
|
I'm using__get_cpuid()to get info on thex86andx86_64processors my programs run on. With GCC on Linux and Mac OS, it seems to compile and run OK without include any header, but how portable is that? Would it work with other compilers? Should I include a header for that?
| It has two leading underscores. Any leading underscore at all is a big hint that the variable or function is not portable.
|
Is there a way to do something like this.
```
printf("Display Time is %S\n",system("date"));
```
I know I can use the time structure to printout the date but I would like to know whether I can do something like this.
| system("date > out.txt");
after read out.txt
or
popen()
|
for example in Python:
```
number = struct.unpack('!L', socket.inet_aton(ip))[0]
ip = socket.inet_ntoa(struct.pack('!L',number))
```
| inet_addr,inet_aton,inet_ntoa, there are quite a few functions, try looking up the documentation.
|
for example in Python:
```
number = struct.unpack('!L', socket.inet_aton(ip))[0]
ip = socket.inet_ntoa(struct.pack('!L',number))
```
| inet_addr,inet_aton,inet_ntoa, there are quite a few functions, try looking up the documentation.
|
OK, when a program tries to access a page which is not there in the physical memory, we say a page fault has occurred. But say, program tries to write to a page which is read-only and is there in the physical memory. What is that fault called?
| According to Intel terminology, it'smemory access violation, aka#AVexception.
(I know, there is [linux] tag, but also there is [x86] tag.)
|
How do I make the functions align at 4-byte boundaries with GCC, target 680x0?
-malign-functions=4does not seem to do the trick, by itself anyway. Some kind of option meant to improve cache performance on 68020 and up perhaps?
| -malign-functions=4should do the trick but it can be overridden with thefunction attributealigned(). Make sure that your code doesn't use this (for example with a macro).
|
Let us say that I declare and initialize
```
int a[3] = {1, 2, 3};
```
How can I later asisgn the entire array in one fell swoop? i.e.
```
a = {3, 2, 1};
```
| If your c compiler supports compound literals, you can usememcpy:
```
memcpy(a, (int[]){3, 2, 1}, sizeof a);
```
If you don't plan to stick any variables in there (you can; isn't C99 amazing?),(int[])can be replaced by(const int[])to put the literal into static memory.
|
If I want to transport a signed long (32 bit integer) across the network what do I do? If I send as a signed long then at other end I won't know (potentially) how remote machine represents signed numbers? So what do I do?
| Just usentohlandhtonland cast or implicitly convert back and forth betweenuint32_tandint32_t.
|
Is there any way to convert C/C++ to Assembly not to HEX.
Not like something that gcc or other compiler done(C/C++ --> ASM --> HEX).
Only Convert It to ASM.
Is there any way to do it by gcc,I mean stop compiler when translate C/C++ to ASM?
with special thanks for your attention,and so sorry for my basic question
| Use the-Soption of gcc, for example:
```
gcc -S hello.c
```
This will give you a filehello.swith assembly instructions.
|
I need to write files to the /etc folder on an embedded system with the root partition mounted as Read Only and have them persist. Can I do this in C or C++ assuming that the application is running as root?
| You can always do the obvious:
```
system("mount -o remount,rw /etc");
```
Most embedded systems should be complete enough that mount is available.
|
I am using Ubuntu 10.10 (64 bit) withgccand I wanted to use a 64 bit integer in my C++ program.
On my system the outputs ofsizeof(long),sizeof(long long int)andsizeof(int64_t)are all 8 bytes (64 bits).
Which qualifier (long,long long, orint64_t) would you recommend for using 64 bit integers?
| int64_t-- This is because it is the most portable representation. The other two could be represented differently on other machines.
|
If I want to transport a signed long (32 bit integer) across the network what do I do? If I send as a signed long then at other end I won't know (potentially) how remote machine represents signed numbers? So what do I do?
| Just usentohlandhtonland cast or implicitly convert back and forth betweenuint32_tandint32_t.
|
Is there any way to convert C/C++ to Assembly not to HEX.
Not like something that gcc or other compiler done(C/C++ --> ASM --> HEX).
Only Convert It to ASM.
Is there any way to do it by gcc,I mean stop compiler when translate C/C++ to ASM?
with special thanks for your attention,and so sorry for my basic question
| Use the-Soption of gcc, for example:
```
gcc -S hello.c
```
This will give you a filehello.swith assembly instructions.
|
I need to write files to the /etc folder on an embedded system with the root partition mounted as Read Only and have them persist. Can I do this in C or C++ assuming that the application is running as root?
| You can always do the obvious:
```
system("mount -o remount,rw /etc");
```
Most embedded systems should be complete enough that mount is available.
|
I have a C console app where I need to output the absolute path to a file given a (possibly) relative path. What is the best way to do this in C in a Windows environment?
| I think you are looking for_fullpath().
|
Could someone say me where I can found the source file where are the definitions of the standard libraries?For example, where is the filestring.cthat contains the definitions of the function prototyped instring.h? And above all, it exists?
| its all in compilled state, some of maybe optimized by asm. You need find sources of your compiler to see definitions
|
While debugging a multithreaded c program using GDB, how do I find out the execution position of individual threads in situations like " the execution of a program hanging midway".
Thanks
| Hit Contol-C to get the(gdb)prompt, and thenthread apply all where.
|
How to put the contents of a 32 bit CPU register in a byte array?
| Basically you need to write inline assembly to read contents of some register. For example - to read ESP register into some int variable (Windows & Visual Studio) - you would do something like this:
```
int stackpointer = 0;
__asm {
mov stackpointer, esp
}
printf("stack pointer: %i\n", stackpointer);
```
|
Assume we have a pointer(e.g., defined as int* p) to the beginning of an array and the size of the array(e.g., 1000). We want to reset all 1000 array values to 0. What is the simplest way?
| The simplest way would be to use memset.
```
memset(p, 0, 1000 * sizeof(int));
```
|
Does there exist a test framework for C that forces race conditions?
Or for C++ and Java, for that matter.
| The Valgrind toolHelgrinddetects (among other things) data races in C or C++ programs that use pthreads.
|
I need to extract hours, minutes and seconds from a string formatted as e.g: "00:53:12" to variables a, b and c.
How would I go about this in C?
Thanks in advance!
| You can usestrptime
```
struct tm tm;
if (strptime("00:53:12", "%H:%M:%S", &tm) != NULL)
printf("hour: %d; minutes: %d; seconds: %d;\n",
tm.tm_hour, tm.tm_min, tm.tm_sec);
```
|
What is the best or recommended method for bit shifting a large amount of binary data in C? I have a 200K binary file and I want to left, then right shift the entire lot.
| If your OS can support it use a memory mapped file. Then do a bit shift It'll be very very efficient.
See this answer for more info:What are the advantages of memory-mapped files?
|
Does there exist a test framework for C that forces race conditions?
Or for C++ and Java, for that matter.
| The Valgrind toolHelgrinddetects (among other things) data races in C or C++ programs that use pthreads.
|
Is there a way to change the defaulta.outto something nicer, likefile.cautomatically becomesfile?
I know one can do this withgcc file.c -o file, but... is there something easier?
| No.
Although if you havemakeavailable, you can just do:
```
make file
```
|
How to formatstruct timespecto string? This structure is returned e.g. byclock_gettime()on Linux gcc:
```
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
```
| One way to format it is:
```
printf("%lld.%.9ld", (long long)ts.tv_sec, ts.tv_nsec);
```
|
Why is:
```
if(x!=y!=z)
```
handled as:
```
x=1
y=1
z=2
```
??
I just noticed it today.
| x != yandx == yreturn booleans.You're comparingzto those booleans.
Neither of them will work they way you want them to.
|
What is the best way to duplicate an integer array? I knowmemcpy()is one way to do it. Is there any function likestrdup()?
| There isn't, andstrdupisn't in the standard, either. You can of course just write your own:
```
int * intdup(int const * src, size_t len)
{
int * p = malloc(len * sizeof(int));
memcpy(p, src, len * sizeof(int));
return p;
}
```
|
I'm used to//to mark a single line comment from Java and Visual Studio and was surprised that this does not exist for Ansi-C. Using/* my comment */is quite annoying. Is there any other way to mark a single line comment when using Ansi-C?
| ANSI-C, no, but the current standard revision allows them, and has done so ever since C99.
|
Recently I foundthis articlethat claims that the idea to preferfor(;;)overwhile(1)for infinite loop came because the C compiler originally available on PDP-11 generated an extra machine instruction forwhile(1).
Btw now even Visual C++ warningstend to favor the former.
How realistic is such attribution offor(;;)idiom?
| The "for(;;)" idiom is explicitly mentioned in the original K&R. That's attribution enough for me :)
|
What is a "verbose build" in C? I can's seem to find a good answer. There's a check box in Pelles C for Verbose Build and I can't figure out what this does. Does it include libraries in with the exe or something?
| No, it simply spits out more messages for you during the building process.
|
Is there a way to loop through all the included/defined header files and then#undefthem all?
If looping is the issue, is there another way to#undefall of them with ease?
| GNU cpp provides a -dM directive to do exactly that, you can list all the defines:
gcc -E -dM -c foo.c
You can then use a sed script to undef them on command line :)
gcc -E -c foo.c | sed 's/#define/#undef/'
or do whatever...
have fun :)
|
I need some clever logging library for a daemon-likeC(notC++) program on Linux. It needs to be open-source. It should support logging to files, maybe sockets etc.
Or at least some good tips or tricks or best practices.
| Usesyslog() . This decouples your in program logging from how the logs are handled.rsyslogis used on most Linux distributions nowadays, and allows great flexibility on how the logs are processed.
|
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,visit the help center.Closed10 years ago.
Please, advise me SDK for emulating a file system? (Windows)
Thanks.
| There are multiple possibilities of applications for windows . I'm usingboxedapp.
|
How do you convert anint(integer) to a string?
I'm trying to make a function that converts the data of astructinto a string to save it in a file.
| You can usesprintfto do it, or maybesnprintfif you have it:
```
char str[ENOUGH];
sprintf(str, "%d", 42);
```
Where the number of characters (plus terminating char) in thestrcan be calculated using:
```
(int)((ceil(log10(num))+1)*sizeof(char))
```
|
Current way:
```
while(read(pipe, input, sizeof(input))>0);
```
Is there a better one with seeking?
| Pipes on computers are like pipes in the "real" world... Data flows from one end to the other, and once it's gone from the pipe there is no getting it back. And like a real pipe there is no knowing when the flow will stop, so there is no meaning to try and find the end of the flow before it actually ends.
|
Is it possible to create (or open existing) C program files in Netbeans without creating an entire project? Can these be later run and compiled?
| You can use Netbeans as fancy oversized editor for C files, but if you want to build program from Netbeans, you will need a project.
|
Any sample on makingEntryElementalign to the right?
I can't figure out how to inherit/override theEntryElement.
Thanks,
Mojo
| This looks near identicalMonoTouch.Dialog: Setting Entry Alignment for EntryElement
See my ownanswerabout overridingCreateTextField.
|
Does it make sense to both write and read on a socket (SOCK_STREAM) in parallel with multiple threads? On Linux. Do those syscalls block each other?
| Yes, it makes sense. Since they are in separate threads they do not block each other.
|
Is it possible to create (or open existing) C program files in Netbeans without creating an entire project? Can these be later run and compiled?
| You can use Netbeans as fancy oversized editor for C files, but if you want to build program from Netbeans, you will need a project.
|
How can I, in C, output a value from a syscall to the Linux console so that it will be visible after admesg? What method do I use for printing?
| You're looking for theprintk()function; some documentation on the types that it supports is found inDocumentation/printk-formats.txt. It is defined inkernel/printk.c.
|
```
class app {
public int x = 3;
static void Main(string[] args)
{
}
}
```
it's possible get the memory address allocated byxvariable?
the example can be inC,C++,C#orD.
I hope it is clear
Thanks in advance
| The ampersand (&) is the "address-of" operator in most C-like languages:
```
int x;
printf("Address of x is %p\n", &x);
```
The return value of&is effectively apointerto its operand.
|
I'm using Netbeans to write a C program. Where do I need to paste my input.txt file for the program to read it if I don't want to specify a directory in the program?
| In the currentworking directorywhere the program executes. You'll have to see where exactly Netbeans causes the binary to be output, but most likely, you will want your input.txt file to be in that same directory. Possibly abinsubdirectory of wherever your source is.
|
The Names array of char* is located in file1.cpp
```
char* Names[] = {
"name1",
"name2",
...
"nameN"
};
```
How do I declare it as "extern" in file2.cpp in order to get the values?
| ```
extern char *Names[];
```
This should probably go in file1.h.
|
How can I, in C, output a value from a syscall to the Linux console so that it will be visible after admesg? What method do I use for printing?
| You're looking for theprintk()function; some documentation on the types that it supports is found inDocumentation/printk-formats.txt. It is defined inkernel/printk.c.
|
```
class app {
public int x = 3;
static void Main(string[] args)
{
}
}
```
it's possible get the memory address allocated byxvariable?
the example can be inC,C++,C#orD.
I hope it is clear
Thanks in advance
| The ampersand (&) is the "address-of" operator in most C-like languages:
```
int x;
printf("Address of x is %p\n", &x);
```
The return value of&is effectively apointerto its operand.
|
I'm using Netbeans to write a C program. Where do I need to paste my input.txt file for the program to read it if I don't want to specify a directory in the program?
| In the currentworking directorywhere the program executes. You'll have to see where exactly Netbeans causes the binary to be output, but most likely, you will want your input.txt file to be in that same directory. Possibly abinsubdirectory of wherever your source is.
|
The Names array of char* is located in file1.cpp
```
char* Names[] = {
"name1",
"name2",
...
"nameN"
};
```
How do I declare it as "extern" in file2.cpp in order to get the values?
| ```
extern char *Names[];
```
This should probably go in file1.h.
|
The Names array of char* is located in file1.cpp
```
char* Names[] = {
"name1",
"name2",
...
"nameN"
};
```
How do I declare it as "extern" in file2.cpp in order to get the values?
| ```
extern char *Names[];
```
This should probably go in file1.h.
|
Looking at man 2 write:
```
"On error, -1 is returned, and errno is set appropriately."
```
But if write(2) just fail, it makes nonsense to write an error message right after...
maybe i should write an error message on stderr or maybe just exit() on the first write error?
What do you think?
| In a typical command line program, error messages shouldalwaysbe written tostderr, that's what it's for.
|
my question is on execution what will happen to parent stack?
```
main()
{
f();
g();
}
f()
{
vfork();
}
g()
{
int blast[100],i;
for(i=0;i<100;i++)
blast[i]=i;
}
```
| The behavior is undefined as perhttp://pubs.opengroup.org/onlinepubs/009695399/functions/vfork.html
the behavior is undefined if the process created by vfork() [...] returns from the function in which vfork() was called [...]
|
When I use C Api for Mysql, I heard that I need to compile with gcc like
gcc $(mysql_config --cflags --libs) source.c
but it is tired using this awkward whenever compile c file using mysql.
isn't there any good ways to compile like
gcc source.c
when using Mysql C api.
please help me!
| Learn how to write a smallMakefile, and you'll simply typemaketo compile your program.
|
I need a way using the Win32 API to force shutdown my machine.
I am currently using Windows 7 but O'd really like if the code would work for Vista and XP.
| Isn'tExitWindowsEx()enough for your needs?
|
I have a C program that invokes a java program but I have a problem:
my java program returns an int [], how can I use JNI to get the result of it in C, since JNI only has CallIntMethod?
| Arrays are objects, so you can useCallObjectMethod(). UseGetIntArrayElements()to access the array elements.
|
my question is on execution what will happen to parent stack?
```
main()
{
f();
g();
}
f()
{
vfork();
}
g()
{
int blast[100],i;
for(i=0;i<100;i++)
blast[i]=i;
}
```
| The behavior is undefined as perhttp://pubs.opengroup.org/onlinepubs/009695399/functions/vfork.html
the behavior is undefined if the process created by vfork() [...] returns from the function in which vfork() was called [...]
|
When I use C Api for Mysql, I heard that I need to compile with gcc like
gcc $(mysql_config --cflags --libs) source.c
but it is tired using this awkward whenever compile c file using mysql.
isn't there any good ways to compile like
gcc source.c
when using Mysql C api.
please help me!
| Learn how to write a smallMakefile, and you'll simply typemaketo compile your program.
|
I work on a library to parse connection information from a satellite modem. It sends this information as an UDP package over the network, which I receive withrecvfrom().
What information do I get via thebufferparameter ofrecvfrom()? Is it only the UDP message field, or do I get more information about the UDP package?
| The buffer will only receive the payload data of the packet. Headers are not included.
|
Do signal handlers have a separate stack, (like each thread have separate stacks)?
This is in Linux/C context.
| From the Linux manual pagesignal(7):
```
By default, the signal handler is invoked on the normal process stack.
It is possible to arrange that the signal handler uses an alternate stack;
see sigaltstack(2) for a discussion of how to do this and when it might
be useful.
```
|
I have a number for example:2.4444444. I need to get first digit after the dot -- in my case it's4. How to implement it?
| How about
```
( (int)(floor( fabs( num ) * 10 ) ) ) % 10
```
|
Is it possible to place a linked list index before the output of result in opencv?
For example, I have code
```
for( ; i!= 0; i= i->h_next )
{
printf("Index number = %d Area = %.2f \n",n, area);
}
```
Now, my question is, how to print this index number? As the values ofiare not in 1,2,3 and so on..
| Maybe try:
```
int cnt = 0;
for ( .. ) {
printf("%d\n", cnt++);
}
```
|
I simply write this:
```
char* test="test";
printf("%s",test[0]);
```
it says seg fault;
then I change toprintf("%s",&test[0]);the error gone
But this is not what I want;
the console print: "test "
how to get just value "t" from that pointer?
| If you want just thet, you should do:
```
printf("%c",test[0]);
```
The format%c, will print a singlechar.
%swill print the entire null-terminated string.
|
I have a number for example:2.4444444. I need to get first digit after the dot -- in my case it's4. How to implement it?
| How about
```
( (int)(floor( fabs( num ) * 10 ) ) ) % 10
```
|
Is it possible to place a linked list index before the output of result in opencv?
For example, I have code
```
for( ; i!= 0; i= i->h_next )
{
printf("Index number = %d Area = %.2f \n",n, area);
}
```
Now, my question is, how to print this index number? As the values ofiare not in 1,2,3 and so on..
| Maybe try:
```
int cnt = 0;
for ( .. ) {
printf("%d\n", cnt++);
}
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.