question
stringlengths
24
425
answer
stringlengths
5
405
the codes is: ``` #define O_ACCMODE 00000003 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) ``` How to understand it?Thank you.
"\000\004\002\006"defines array of 4 bytes/chars, we can replace it with: char array[4] = {0, 4, 2, 6}; x&3 means - get only far right 2 bits in integer, basically it is equivalent ofx%4 so, this macro do:array[ x % 4 ]- takes proper value based on index
I need to get PID of foreground app programatically(in C or Obj C) in OS X. How to solve the following problem?
This should do it: ``` pid_t pid=NSWorkspace.sharedWorkspace.frontmostApplication.processIdentifier; ```
I am looking for a decent one line c statement to keep a character between'0'and'9'on increment What I have right now is this: ``` char c; ... c = (((c % 48 ) + 1) % 10) + 48; ``` Is there a better way of dong this?
Use'0'instead of hardcoding its ASCII value. Also I likec - '0'better thanc % '0'; it matches up with the+ '0'better. ``` c = (c - '0' + 1) % 10 + '0' ```
I want to know, ifWriteProcessMemoryorReadProcessMemoryfunctions access program code, or data. Thanks.
It can access both. Program text and data live in the same address space, and are somewhat intermingled for things like read-only data.
Is there a C or C++ library available for parsing, editing, and writing/etc/network/interfaceson Linux (in the form described athttp://manpages.ubuntu.com/manpages/hardy/man5/interfaces.5.html)?
http://augeas.net/ Augeas is a configuration editing tool. It parses configuration files in their native formats and transforms them into a tree. Configuration changes are made by manipulating this tree and saving it back into native config files.
i Want to catch keyboard key on a real time game, for example im printing each 0,3s with usleep(300000) something like that ``` // ##### // ##a## // ##### ``` and I want to move my 'a' arround with the directional keyboard key (left, right...) the problem is each time I call read the program is paused till I enter a key
You have two choices: multi-threadingasynchronous I/O
I am trying to extract the minor device number from the tty_nr attribute in /proc/pid/stat. According to the documentation it is said that, minor device number is a combination 0-7 and 20-30 bits in tty_nr. How can I extract these bits from the tty_nr number?
There are macros already defined for this purpose. Use theMAJOR()andMINOR()macros that are defined inlinux/kdev_t.h.
As the title suggests how do i print 17 in the hexadecimal format(0x11). I have triedprintf("%04x",number);but it prints the number as 0011(correct but not what i want).
Try this its clean and simple. Hexadecimal ->printf("%#x",17); Octal ->printf("%#o",17); More about#. Here's the linkhttp://www.cplusplus.com/reference/cstdio/printf/
As the title suggests how do i print 17 in the hexadecimal format(0x11). I have triedprintf("%04x",number);but it prints the number as 0011(correct but not what i want).
Try this its clean and simple. Hexadecimal ->printf("%#x",17); Octal ->printf("%#o",17); More about#. Here's the linkhttp://www.cplusplus.com/reference/cstdio/printf/
I have a strange line in my stacktrace that I want to investigate further: ``` 12 libsystem_c.dylib 0x3aa272dc free + 168 ``` If I understand correctly, libsystem_c is C standard library. Is the version used in the iOS open-sourced? Where can I get that source?
To be more specific, I think it is hosted here:https://opensource.apple.com/source/Libc/
I see everyone recommends just using openGL and some others but I don't wanna. I just want to know if graphic.h will only compile in turbo c and not with gcc, Thanks
You might getgraphics.hcompiled (as#included part of some sources), but the linking (coming after the compilation) will fail, as gcc's linker (ld) would not link the compilation's result against the library (graphics.lib) implementing whatgraphics.hprototyped.
I have Linux and I have a physical address: (i.e. 0x60000000).I want to read this address from user-space Linux program. This address might be in kernel space.
You need a kernel driver to export the phyisical address to user-level. Have a look at this driver:https://github.com/claudioscordino/mmap_alloc/blob/master/mmap_alloc.c
I have Linux and I have a physical address: (i.e. 0x60000000).I want to read this address from user-space Linux program. This address might be in kernel space.
You need a kernel driver to export the phyisical address to user-level. Have a look at this driver:https://github.com/claudioscordino/mmap_alloc/blob/master/mmap_alloc.c
This question already has an answer here:how to use the compiling time as automatic versioning-info?(1 answer)Closed9 years ago. So what I want is to have some preprocessor which gives the time of compilation. So that I can know which version of the program I'm running, by printing that time. Is it possible?
``` #include <stdio.h> int main(void) { printf("%s %s\n", __DATE__, __TIME__); return 0; } ``` Otherstandard predefined macros
This question already has an answer here:how to use the compiling time as automatic versioning-info?(1 answer)Closed9 years ago. So what I want is to have some preprocessor which gives the time of compilation. So that I can know which version of the program I'm running, by printing that time. Is it possible?
``` #include <stdio.h> int main(void) { printf("%s %s\n", __DATE__, __TIME__); return 0; } ``` Otherstandard predefined macros
In C/C++ when I want to find sum of two chars - I get result in int.For example: ``` #include <stdio.h> int main(){ char a = 'a', b = 'b'; printf("%d + %d = %d\n", sizeof(a), sizeof(b), sizeof(a + b)); return 0; } ``` Prints ``` 1 + 1 = 4 ``` Why?
Because althoughaandbare each of typechar, the expressiona + bis of typeint. Anytime you do math with char types, they are converted to int before doing the actual calculations.
How do use vector or in-built sort function in C++ with most of the language in C? I am trying to just sort an array for a C program. Can it explained with a simple code with sort implementation? I am very new to C++.
If you want to sort inCthen you should useqsort. If you want to sort inC++then you should usestd::sort
Which of the following declaration is the standard and preferred? ``` int x = 7; ``` or ``` int x(7); ```
``` int x(7); ``` isnotthevalidway of declaring & initializing a variable in C; I suggest you to get a good book for learning C and use a good compiler.
Which of the following declaration is the standard and preferred? ``` int x = 7; ``` or ``` int x(7); ```
``` int x(7); ``` isnotthevalidway of declaring & initializing a variable in C; I suggest you to get a good book for learning C and use a good compiler.
I'm modifying a linux filesystem and I would like to know if there a way to get astruct file *from an absolute pathname? Specifically the struct defined inlinux/fs.h.
I know this is a little late, but for anyone looking for an answer to this I used theopenfunction on the pathname.
I'm modifying a linux filesystem and I would like to know if there a way to get astruct file *from an absolute pathname? Specifically the struct defined inlinux/fs.h.
I know this is a little late, but for anyone looking for an answer to this I used theopenfunction on the pathname.
In xcode 5 I get this warning: "implicit declaration of function free is invalid in c99" How should I free my c structures if I can't use the function free()?
You should include<stdlib.h>.
I have a register which 31 bit wide ,Now I am confused between two number that could be used as last address 31 bit scheme . Would 0x7fff-fffc or 0x80000000 be the last address can be used in 31 scheme.
Addresses start at zero. So0x7FFFFFFFif you are addressing bytes.0x7FFFFFFCif you are addressing 32-bit words.
When using theC interface to LLVM, how do I determine whether twoLLVMTypeRefs represent the same type?
IIUC, if the two types were created in the sameLLVMContextit should be the same pointer, since types are uniqued in LLVM. C API functions usewrapto "convert" C++TypetoLLVMTypeRef, which just usesreinterpret_caston the pointer.
I have a register which 31 bit wide ,Now I am confused between two number that could be used as last address 31 bit scheme . Would 0x7fff-fffc or 0x80000000 be the last address can be used in 31 scheme.
Addresses start at zero. So0x7FFFFFFFif you are addressing bytes.0x7FFFFFFCif you are addressing 32-bit words.
If I call a function in C and pass in a struct (not by pointers nor references for those c++ readers), it copies the object. If I pass in a struct with an array in it, it copies the array (as stated by professor in class). But what happens if I pass in a struct that contains a circular reference back to the object. How does it copy the whole struct?
It copies the struct, and the pointer inside the copied struct contains the address of the original object.
``` void empty() { } ``` will be compiled to ``` push ebp mov ebp, esp ret ``` How do I declare the function so that it has no "decoration" code? just plainret. If that is not possible, is this possible to define completely assembler function inside the.Cfile? It is possible to define assembler function in the.asmfile.
Declare the function with the__declspec(naked)modifier.
is this valid C code ? Is possible to have switch in switch ? ``` switch (i){ case 1: switch(c){ case 1: c = 0; break; case 3: c = 5; break; } case 2: // another code } ```
Yes, to have switch in switch is valid. § 6.4.2The switch statement 4Switch statements can be nested; a case or default label is associated with the smallest switch enclosing it.
If I call a function in C and pass in a struct (not by pointers nor references for those c++ readers), it copies the object. If I pass in a struct with an array in it, it copies the array (as stated by professor in class). But what happens if I pass in a struct that contains a circular reference back to the object. How does it copy the whole struct?
It copies the struct, and the pointer inside the copied struct contains the address of the original object.
``` void empty() { } ``` will be compiled to ``` push ebp mov ebp, esp ret ``` How do I declare the function so that it has no "decoration" code? just plainret. If that is not possible, is this possible to define completely assembler function inside the.Cfile? It is possible to define assembler function in the.asmfile.
Declare the function with the__declspec(naked)modifier.
I'm debugging my C code and I want to know the value of a chars array. the problem is that it is seen like this: 0x63d7c4c8 "\327\220\327\250\327\225\327\236" how can I convert to Hebrew chars, via eclipse debug window?
``` bash ~ $ printf "\327\220\327\250\327\225\327\236\n" ארומ bash ~ $ ``` Not sure you can change it in the debug window, but take a lookhere.
This question already has answers here:C++ : why bool is 8 bits long?(7 answers)Closed9 years ago. Forbool, it's 8 bit while has only true and false, why don't they make it single bit. And I know there'sbitset, however it's not that convenient, and I just wonder why?
The basic data structure at the hardware level of mainstream CPUs is a byte. Operating on bits in these CPUs require additional processing, i.e. some CPU time. The same holds forbitset.
I executed the following code. ``` #include <stdio.h> int main() {char *a="awake"; printf("%s\n", *(a+1)); return 0; // expected out_put to be wake } ```
You're dereferencing the pointer, which makes it acharbut trying to output a string. Change your print statement toprintf("%s\n", a+1);
What mark does a language leaves on a compiled library that we need language bindings if we have call its functions from a different language? object code looks 'language free' to me. While learning OpenGL in c in Linux environment I have across language bindings.
Binding provides a simple and consistent way for applications to present and interact with data. Source: The tag under your question
I executed the following code. ``` #include <stdio.h> int main() {char *a="awake"; printf("%s\n", *(a+1)); return 0; // expected out_put to be wake } ```
You're dereferencing the pointer, which makes it acharbut trying to output a string. Change your print statement toprintf("%s\n", a+1);
When I compile a C project it can take about 90 seconds even though I use a fast Intel I7 CPU. Is it because compilation is a low-level task or why are my build times so long? My environment is the Nios 2 IDE for Altera DE2 FPGA.
if your project is managed by Makefile, try "make -jn" to trigger mul-threads in compiling, n is thread num for compiling, e.x. "make -j10"
I know a pointer to a function is 8 byte because of virtualization but why a pointer to a pointer to a function is 8 byte? ``` typedef void(*fun())(); sizeof(fun*); // returns 8 byte ```
If you have a 64-bit system with 8-bit bytes (and it sounds like you do), probablyallpointers will be 8 bytes in size. Virtualization doesn't have anything to do with it.
Is it a standard to have only dynamic libraries mostly without their static version? I am particularly asking about math library. In my fedora 17 (linux machine on Intel 32 processor), I have latest gcc and it has libm-2.15.so and symbolic link file libm.so but there is no libm.a. Is libm.a missing on my system?
Install the static libraries: ``` # yum install glibc-static ```
Is it possible to do multiple operations in increment part of for loop in C/C++? Something like this: ``` int a = 0, b = 0, c = 5; for(; a < c; increase a by 1 and increase b by 2) ```
Use the comma operator: ``` for (; a < c; ++a, b += 2) ```
I'm trying to use the functionsisDigit()I have the correct include statement,#include <ctype.h>however, I seem to be getting a warning when I compile, ``` warning: implicit declaration of function 'isDigit' is invalid in C99 [-Wimplicit-function-declaration] ``` The line that compiles the warning isif(isDigit(atoi(inputLine)) {can anyone give me feedback as to what I am missing here? Thanks.
include this header file in your program :#include<ctype.h>
I want to write a simple C program which would print the number of times that program itself got executed (by user). for example, output should beYou are executing this program 3rd time I first thought of using file handling but later came to know aboutvolatileandregister. Is there any use ofvolatileorregisterin this context?
No,volatileandregisterare only meaningful within the same run. Instead, store a counter in a file.
``` #ifndef _WINDOWS if(condition) { printf("to do in linux"); } else #endif { printf("should work in both linux and windows..."); } ``` My question: does this code work for both in linux and windows?
You have more logic than you need - you can just do this: ``` #ifndef _WINDOWS printf("to do in Linux"); // ... #endif printf("to do in both Linux and Windows"); // ... ```
Suppose I have the following code. While debugging, I want Eclipse to stop when it has done 1 million iterations. How to do this? I cannot manually do 1 million times. ``` for(int i = 0; i < 10000000; i++) { //some code } ```
You can put conditional break point in eclipse: Put a breakpointRight-click->PropertiesTurn on "condition" check-boxPut condition codei == 1000000
Does such a function result in a dangling pointer? ``` int *foo () { int a[2] = {2, 3}; int *p = NULL; p = a; return p; } ```
Yes. You are returning a pointer to an array with automatic storage duration. When the function returns the pointer is invalid.
Whether there are situations when the object needs to be created in memory to a certain address? Where it can be necessary (example)? Thank you.
Take a look at placement new: "What uses are there for "placement new"?" Good examples are writing your own memory allocator, garbage collector, or trying to precisely lay out memory due to cache performance. It's a niche thing, but sometimes very useful.
This question already has an answer here:Pointer to a specific fixed address(1 answer)Closed9 years ago. I need to write 0x00001234 in the address 0x8000000, is it possible in C?
If you work with hardware register in embedded system then standard way is: ``` int volatile * const p_reg = (int *) 0x8000000; *p_reg = 0x1234; ``` You can have a lot of problems with optimizing compiler, if you omitvolatile
I want to use getaddrinfo() but get only the first result. more specifically, I want the function to first scan the hosts file and fetch the first result found, and only if not found in hosts I want to query the dns server. is it possible? thanks.
You can't. It behaves as documented. You only have touseone result: that's up to you.
Hi I have this book with a practice question which I am unable to answer. And no...this is not a homework question. This is my self study from a book recommended to me called: "Computer systems, A programmer's perspective" Here is the question: Any help is appreciated!
lengthis unsigned, so if you pass0for that parameter,length - 1will beUINT_MAX, not-1like you want it to be; therefore the loop will run and you'll make acceses outside the size ofa.
When to use sqlite3_blob_write and sqlite3_blob_read? When this functions is more useful than sqlite3_prepare_v2 + sqlite3_bind_blob?
You use them when the blobs are too large for the memory available for your program, or when you need to access only a small part of a large blob. This matters mostly in embedded applications.
In my programming class we are not allowed to use || && and ! for this assignment. How can you do a "not" statement without the use of !? Also, how to do && would be useful but I think I can figure it out. (we can use % / * pow abs ln + -)
!ais equivalent to1-a, providedais guaranteed to take only the values 0 or 1.
I have achar* linefromfgets (line , 255 , pFile)that I want to add the character "#" to the end of. How do I do this in c++? Something like ``` while ( fgets (line , 255 , pFile) != NULL ) { line = line + '#' } ```
``` strcat(line, "#"); ``` Of course the correct answer is to usestd::stringinstead.
``` #include <stdio.h> int main() { printf(5 + "abhishekdas\n") ; return 0 ; } ``` The output of the program ishekdas. How is it working? Shouldn't it show error? How is it possible to write something like5 + "abhishekdas"insideprintffunction ?
``` 5+"abhishekdas\n" ==> "abhishekdas\n"+5 ==> &"abhishekdas\n"[5] ==> "hekdas\n" ```
How to convert a 32-bit integer value to an ip-address? I am havingint value=570534080and want to convert it to192.168.1.34.
``` #include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main(void) { int value=570534080; struct in_addr addr = {value}; printf( "%s", inet_ntoa( addr ) ); return 0; } ``` Test:http://ideone.com/RCDgj4 For Windows use#include <winsock2.h>
``` #include <stdio.h> int main() { printf(5 + "abhishekdas\n") ; return 0 ; } ``` The output of the program ishekdas. How is it working? Shouldn't it show error? How is it possible to write something like5 + "abhishekdas"insideprintffunction ?
``` 5+"abhishekdas\n" ==> "abhishekdas\n"+5 ==> &"abhishekdas\n"[5] ==> "hekdas\n" ```
How to convert a 32-bit integer value to an ip-address? I am havingint value=570534080and want to convert it to192.168.1.34.
``` #include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main(void) { int value=570534080; struct in_addr addr = {value}; printf( "%s", inet_ntoa( addr ) ); return 0; } ``` Test:http://ideone.com/RCDgj4 For Windows use#include <winsock2.h>
Is stdin is a pointer, as I have seen its usage in fgets(). I used '0' as we use for read or write mistakenly for stdin and got a segfault during fgets. Is STDIN macro and 0 are the same. Is stdin is a file pointer. Please explain about this
stdin is aFILE *fromstdio.h ``` STDIN_FILENO == fileno(stdin) ``` STDIN_FILENOis inunistd.hand is used for functions likewrite, whereas stdin as a File * is used for stdio functions likeprintf
This question already has answers here:Print part of a string in C(4 answers)Closed9 years ago. Is it possible inCto set a number of chars to be output from string? ``` char const *str = "abcdefgh"; printf("%???s", str); ``` What should be placed instead of ??? to outputabc?
Yes, you could use a precision specifier, which would look something like this ``` printf("%.3s", str); // this prints "abc" ```
How can I make a pointer point to the last byte of the physical memory and access its data? Is this even possible?
No, since the language C does not specify the underlying memory architecture. On select OS/architecture you may in an OS dependent or creative fashion.
How can I make a pointer point to the last byte of the physical memory and access its data? Is this even possible?
No, since the language C does not specify the underlying memory architecture. On select OS/architecture you may in an OS dependent or creative fashion.
Is there a way to put an array inside another array without using loops? This loop feels a bit weird: ``` uint8_t buf0[50]; populate_buf( buf0 ); uint8_t buf1[100]; buf1[0] = 'S'; for ( uint8_t i = 0; i < 50; i++ ) buf1[1+i] = buf0[i]; ```
``` memcpy(&buf1[1], &buf0[0], sizeof buf0); ```
Is there a way to put an array inside another array without using loops? This loop feels a bit weird: ``` uint8_t buf0[50]; populate_buf( buf0 ); uint8_t buf1[100]; buf1[0] = 'S'; for ( uint8_t i = 0; i < 50; i++ ) buf1[1+i] = buf0[i]; ```
``` memcpy(&buf1[1], &buf0[0], sizeof buf0); ```
I would like to dynamically allocate memory for an input string whose size is unknown at the time of input,with exact precision, i.e. if the string is "stack" I would like to allocate 6 bytes only. I guess the only way is to keep on increasing the upper limit of the array depending on the input but I am unable to figure out the piece of code.
strdup()is your friend. ``` char *p = strdup("stack"); ```
If I encounterfeof()and thenstatshows that the file has grown, is there a way to read the added data without doing afclose()andfopen()?
Yes. You can callclearerron the file, or perform any seek opereration such asfseek(f, 0, SEEK_CUR).
given this definition: ``` typedef enum mytype { FIRST = 0, TWO = 1, Three = 2 } mytype_t; ``` and ``` somefunction(mytype_t param_one) { (some code) } ``` How I can get the integer value of param_one inside the function or assign it to a integer variable?
You just use it - it is an integer type already: ``` int x = param_one; ```
In C,stdinis a valid file pointer, thus we could usestdin(and the 2 others) with the "file" version of the input functions if we want or need to. Why might us need to (Rather than just pipe in from shell)? Could anyone come up with some examples please?
Here's an example: ``` FILE * input = argc == 2 ? fopen(argv[1], "r") : stdin; fgets(buf, sizeof buf, input); ``` Now you can use your tool asmagic data.txtand asmagic < data.txt.
In C,stdinis a valid file pointer, thus we could usestdin(and the 2 others) with the "file" version of the input functions if we want or need to. Why might us need to (Rather than just pipe in from shell)? Could anyone come up with some examples please?
Here's an example: ``` FILE * input = argc == 2 ? fopen(argv[1], "r") : stdin; fgets(buf, sizeof buf, input); ``` Now you can use your tool asmagic data.txtand asmagic < data.txt.
This question already has answers here:How do you check the windows version in Win32 at runtime?(2 answers)Closed10 years ago. I wanted to ask, is there any possibility to determine the Windows version via the application, I have made some research, but haven't found, Thank you in advance ^^
Err... How aboutGetVersionEx()?
This question already has answers here:How do you check the windows version in Win32 at runtime?(2 answers)Closed10 years ago. I wanted to ask, is there any possibility to determine the Windows version via the application, I have made some research, but haven't found, Thank you in advance ^^
Err... How aboutGetVersionEx()?
i am trying query windows for a list of all usb hdi devices that are connected to my computer. Somehow i the microsoft dokumentation is not exactly to helpfull for me. Can anybody please point me to something? I would like to use c/c++ Thanks!
here you can find anything you want:https://github.com/signal11/hidapi
Could someone outline how to use c99 when my c-programs compile? I cannot use the for(int i = 0...) loop without it. Note - all the answers I have found are either outdated, or for the cygwin compiler. thanks in advance
In the project build settings set-std=c99in the "Other flags" text box.
I am very beginner in c and I am reading now the classic example of the TicTacToe game. I am not sure about what thisreturnstatement does: ``` {..... return (ch == X) ?O :X; ``` This must be some conditional statement on the variable ch (that in my case stands for the player (X or O) but I am not sure about its meaning. Can anyone please tell me what does it do?
It means ``` if (ch == X) return O; else return X; ```
It's quite a simple question but has it's gotchas.So here it goes. Does each new Lua state created using the lua_newthread C API method get it's own individual LUA_REGISTRYINDEX accessible through it's new created Lua state or does it use a global shared LUA_REGISTRYINDEX?
All threads of the same Lua state share a single registry, as can be seen in thesource. Different Lua states have different registries.
Using theCprogramming language, what is the best way to make a multicore Red Hat Linux processor, use only one core in a test application?
There is aLinux system callspecifically for this purpose calledsched_setaffinity Forexample, to run on CPU 0: ``` #include <sched.h> int main(void) { cpu_set_t mask; CPU_ZERO(&mask); CPU_SET(0, &mask); result = sched_setaffinity(0, sizeof(mask), &mask); return 0; } ```
It's quite a simple question but has it's gotchas.So here it goes. Does each new Lua state created using the lua_newthread C API method get it's own individual LUA_REGISTRYINDEX accessible through it's new created Lua state or does it use a global shared LUA_REGISTRYINDEX?
All threads of the same Lua state share a single registry, as can be seen in thesource. Different Lua states have different registries.
Using theCprogramming language, what is the best way to make a multicore Red Hat Linux processor, use only one core in a test application?
There is aLinux system callspecifically for this purpose calledsched_setaffinity Forexample, to run on CPU 0: ``` #include <sched.h> int main(void) { cpu_set_t mask; CPU_ZERO(&mask); CPU_SET(0, &mask); result = sched_setaffinity(0, sizeof(mask), &mask); return 0; } ```
Using theCprogramming language, what is the best way to make a multicore Red Hat Linux processor, use only one core in a test application?
There is aLinux system callspecifically for this purpose calledsched_setaffinity Forexample, to run on CPU 0: ``` #include <sched.h> int main(void) { cpu_set_t mask; CPU_ZERO(&mask); CPU_SET(0, &mask); result = sched_setaffinity(0, sizeof(mask), &mask); return 0; } ```
I'm having a problem casting, so is there a way to cast a type of: ``` char *result; ``` to a type of ``` char *argv[100]; ``` ? If so, how would I do this or is there a safe way to do this?
char * resultis a string and char * argv[100]is array of strings. You cannot convert string into array of strings. However, you can create an array of strings where the first array value is result. ``` argv[0] = result; ```
Is there anyway I can load a c pointer into a specific register like eax? I want to take an array, like int array[10], and load array (or &array[0], but either way they're the same thing) into register eax.
This is compiler dependent. Gcc has an extension to theregisterkeyword ``` register unsigned* p __asm__("eax") = a; ```
Is there a way to get my Spotify play history using either their js or C APIs? I saw a couple of examples, but that was using their outdated API version.
Spotify play history is not available through any API. Disclaimer: I'm a Spotify employee.
Will it be precise to say that in ``` void f() { int x; ... } ``` "int x;" means allocatingsizeof(int)bytes on the stack? Are there any specifications for that?
Nothing in the standard mandates that there is a stack. And nothing in the standard mandates that a local variable needs memory allocated for it. The variable could be placed in a register, or even removed altogether as an optimization.
Is there a way to get my Spotify play history using either their js or C APIs? I saw a couple of examples, but that was using their outdated API version.
Spotify play history is not available through any API. Disclaimer: I'm a Spotify employee.
I'm compiling a C code in Xcode 4.6.3, however I don't know which compiler I'm using. I need to use gcc 4.2. Thanks in advance.
If youreallyneed to change to gcc, you can do so in the build settings:
When I do something like ``` typedef long a; extern a int c; ``` It gives me error :two or more data types in declaration specifiers.Why? EDIT ``` typedef long a; extern a c; ``` works fine.So why not above?
It's a typedef, not a macro. The compiler doesn't seeextern long int c, it seesextern a int c, which contains two different types (aandint).
Code: ``` int main() { char *name=NULL; int n; printf("\nenter the string\n"); scanf("%s",name); n=strlen(name); printf("%d",n); return 0; } ``` I am getting segmentation fault. Whats wrong with the code? I have includedstdio.h,stdlib.h,string.h.
You didn't allocate any memory for pointer to charname. Example: ``` char * name = malloc( sizeof( char ) * MAX_STRING_LENGTH ) ; ```
Code: ``` int main() { char *name=NULL; int n; printf("\nenter the string\n"); scanf("%s",name); n=strlen(name); printf("%d",n); return 0; } ``` I am getting segmentation fault. Whats wrong with the code? I have includedstdio.h,stdlib.h,string.h.
You didn't allocate any memory for pointer to charname. Example: ``` char * name = malloc( sizeof( char ) * MAX_STRING_LENGTH ) ; ```
In my program the user inputs the number of decimal places he requires in an output. I save this input as deci. How do I use this variabledecias a precision modifier? Sample: Input a number: 23.6788766 Input number of decimals: 2 Output: 23.67
If it is C you can do: ``` float floatnumbervalue = 42.3456; int numberofdecimals = 2; printf("%.*f", numberofdecimals, floatnumbervalue); ```
Let the first row be: ``` #define TAG_LEN 32 ``` Now, I need to concatenate it with a literal string constant; something like that: ``` puts("Blah" [insert your answer] TAG_LEN); // I need "Blah32". ```
``` #define STR_NOEXPAND(tokens) # tokens #define STR(tokens) STR_NOEXPAND(tokens) puts("Blah" STR(TAG_LEN)); ```
My compiler warns:operation on j may be undefined Here's the C code: ``` for(int j = 1; pattern[j] != '\0' && string[i] != '\0';){ if(string[i+j] != pattern[j++]){//this is on the warning found = 0; break; } } ``` Is that undefined?
YES.string[i+j] != pattern[j++]is having two different execution based on variablejwithout anysequence pointin between. So it is example ofundefined behaviour.
So I was using CGo for a number crunching web app and it happens that CGo seems faster. Is there any that I can use CGo on Google App Engine Go runtime.
Nope. CGo is not supported yet, and perhaps never will. This isPaaSafter all and they need to isolate the platform. But you never know. Perhaps a restricted version.
So I was using CGo for a number crunching web app and it happens that CGo seems faster. Is there any that I can use CGo on Google App Engine Go runtime.
Nope. CGo is not supported yet, and perhaps never will. This isPaaSafter all and they need to isolate the platform. But you never know. Perhaps a restricted version.
Here are some links documenting the functions that I want to use: xmlNewNodexmlNewChildxmlNewProp Since these functions use dynamic memory allocation, I want to do error checking, but I couldn't find information about behavior of these functions in case of an error. Do these functions simply return NULL on failure ?
Yes, like most of thelibxml2functions which return pointers, these returnNULLon failure.
I'm trying to implement HTTP/1.1 protocol using Socket in C language. I just want to know if the Body inside a request can contain strings like: "\r\n" i.e a CR LF. Also, please let me know if there is a maximum limit to the number of characters inside the body.
There are no limits to the size or content of the body in an HTTP request or response.
Are the following same: ``` extern int a[]; ``` and ``` extern int *a; ``` I mean, are they interchangable?
No they are not. You'll see the difference when you try something likea++. There's plenty of questions about the difference between pointers and arrays, I don't think it's necessary to write more here. Look it up.
Is there a OpenCV way to (gaussian) smooth just 1 channel in a 3 channel (RGB) image? Any of Python or C or C++ OpenCV is fine.
You can useSplitto split the image into its channels and then useFilter2Don one of the components. ``` Split(src, src_r, src_g, src_b) Smooth(src_r, dst_r) Merge(dst_r, src_g, src_b, dst) ```
I've created a Plain C project in Qt Creator in Linux, but I'm getting this error: ``` error: 'for' loop initial declarations are only allowed in C99 mode note: use option -std=c99 or -std=gnu99 to compile your code ``` What should I put in my *.pro file to enable C99?
``` QMAKE_CFLAGS += -std=c99 ``` This worked for me, even though it is not documented and the intellisense doesn't recognize it.
I've created a Plain C project in Qt Creator in Linux, but I'm getting this error: ``` error: 'for' loop initial declarations are only allowed in C99 mode note: use option -std=c99 or -std=gnu99 to compile your code ``` What should I put in my *.pro file to enable C99?
``` QMAKE_CFLAGS += -std=c99 ``` This worked for me, even though it is not documented and the intellisense doesn't recognize it.
I have the coordinates of 4 points, and I want to to draw a quad based on those coordinates in opencv! is there in function that can based on those point draw a region! I know thatrectcan do that but I know I'll not always have a rectangle!
I would suggest to use polygon drawing withpolylinesorfillPolyseedrawing functionsfor more information.
How One can access a variable from ONLY two functions that a file consists of total five functions.(No global or static declaration)
You can't in C; the file is the compilation unit that defines the boundaries forstaticvariables of that sort, since anyone who can edit or view that file could work with all of the functions in it. If you really need to separate visibility, you have to split the functions into multiple files.
When I press Ctrl+c then SIGINT will be passed to signal() . What value will be pass to the system call signal() when i press a key A ?
No signal will be raised. The purpose of signals is to inform about a special condition outside normal program flow. Processing input, like the letter A, is part of normal program flow. These two are completely separate, and have different goals. If you're on UNIX, typeman signalon your console.
I have developed C/C++ binaries and I have android app. I have ported binaries on linux base server and now I would like to use this binaries in my android app. Can i call this binaries from my app? Is it possible, please excuse me as I don't have any idea about this.
Here you will find a nice tutorial to implement C code into your Android Project: JNI tutorial