2018-10-22         Hyman

How to use more than 3 GB in a process on 32-bit PAE-enabled Linux app?

PAE (Physical Address Extension) was introduced in CPUs back in 1994. This allows a 32-bit processor to access 64 GB of memory instead of 4 GB. Linux kernels offer support for this starting with 2.3.23. Assume I am booting one of these kernels, and want to write an application in C that will access more than 3 GB of memory (why 3 GB? See this).How would I go about accessing more than 3 GB of memory? Certainly, I could fork off multiple processes; each one would get access to 3 GB, and could communicate with each other. But that's not a realistic solution for most use ...

 c                     6 answers                     65 view
 2018-10-22         Natalie

Segmentation fault on memcpy() function

I have the following memory base address which contains some data of 256 bytes:#define TX_PTR 0x40000008Now I have the following array which will store the data from TX_PTR.unsigned int tx_arr[64];int i = 0;for (i=0; i<64;i++){ tx_arr[i]=0;}When I try to memcpy the data from the memory base address to the array by:memcpy(&tx_arr, TX_PTR, 2*32*sizeof(int));I get a segmentation fault.I am running this code in linux. What could be the problem here? I am running freertos and openamp on a zynq board.From this comment, I am led to believe that the "memory" is implem...

 c                     1 answers                     73 view
 2018-10-22         Wright

How to optionally pass variable arguments in C

Consider below function:void foo(int n,...);I need to call this function, "optionally" passing variable arguments. Is it possible?Something like this:foo(10, (bIsJobDone ? "OK" : xxx) );I am not able to figure out what to put in place of xxx (xxx should convert to nothing) and also how to avoid "," after 10, if I don't have to pass any variable arg to foo?Note: i can't change signature of "foo". As long as you got the called function correctly prototyped and defined (not easy...),calling it with one or two parameter, depending on a condition is easy:if(bIsJobDone){ fo...

 c                     3 answers                     76 view
 2018-10-22         Dick

How can I find the number of unique characters in a string?

I have found nothing particular for this purpose.I am trying to figure out a function that counts each of the characters' occurrences in a string, so that I can pull them out at the end from the length to find how many homogeneous characters are used in that string.I've tried with nested loop, the first to apply and the second to scan the string and conditionally fulfill the character if it does not appear elsewhere in the string.Well it didn't work well.This is useful if you are willing to limit someone to type lazy names such as "aaaaaaaaaaaaa" This method has O(n^2) c...

 c                     3 answers                     32 view
 2018-10-22         Paula

Count number of words in input line. Where word is just consistency, where first character is only letter

Exact formulation:Write a program, which counts numbers of words in the input line. In word means consistency, where the first character must be a letter.Examples of inputs and outputs:Input: one 2two threeOutput: 2Input: one two three four five 6sixOutput: 5Input: 789878moer and moreOutput: 2Input: something like 8this Output: 2Program:#include <stdio.h>#define YES 1#define NO 0int main() { int c, nw, inword, first_char; inword = first_char = NO; nw = 0; while((c = getchar()) != EOF) { if (c == ' ...

 c                     1 answers                     53 view
 2018-10-22         Elton

C socket: problem with connect() and/or accept() between clients. 111: Connection refused

Hello ladies and gents, I'm having a bit of problem with accept(). I have a multiple clients and one server. The clients can connect and communicate just fine with server. But at one point, I need some clients to be directly connected to each other and I'm having a bit of difficulty there. The clients have bunch of threads going on, where one of them is handle_connection() and it has a while(1), looping forever to listen() and accept() whatever incoming connections. Whenever a client tries to connect() to other client, connect() returns an error, 111: Connection Refused. I ...

 c                     1 answers                     37 view
 2018-10-22         Osborn

Producer consumer sync using two threads giving unsual serial output

I'm solving a producer / consumer problem using two threads. I think I've done something wrong because it seems to give the same serial output every time. What's the problem?#include <stdio.h>#include <semaphore.h>#include <pthread.h>#include <unistd.h>#include <stdbool.h>sem_t empty, full, mutex;int bound[5];int a,b;void *producer(void *arg) { for (int i = 0; i < 15; i++) { sem_wait(&empty); sem_wait(&mutex); printf("%d is produced\n", i); sleep(1); bound[(++a) % 5] = i; sem_post(&m...

 c                     2 answers                     89 view
 2018-10-22         Hiram

Estimating running time of a "C language" code block: Is it possible?

I want to write a function in C language such that it must check millions of parameters and if all of them are true, function returns true as well, otherwise, it returns false.However, estimating the time of this operation is important, meaning that we need to know it takes how many milliseconds. (An approximate time would be enough.) We need to know this time to know the throughput of this function.Note: This parameters are read locally from a file and we use an ordinary computers. Rather than estimating the time, measure it. Modern CPU architecture performs optimizati...

 c                     1 answers                     21 view
 2018-10-22         Ivy

AVX2 64-bit unsigned integer comparison

I'm trying to compare two __m256i (4 packed 64-bit integers). To do so, I use the _mm256_cmpgt_epi64 function.The function works as expected except for a few comparisons, as if the function did not consider the largest bit of the 64-bit integer. As shown below in the second and third comparisons.Here a MCVE, where I expect each 64-bit integer from a to be larger than its peer from b (thus cp should be 0xFFF...FFF):#include <immintrin.h>#include <x86intrin.h>#include <stdio.h>#include <inttypes.h>// gcc mcve.c -mavx2 -madx && ./a.outint print_...

 c                     1 answers                     82 view
 2018-10-22         Erica

Embedded Firmware Architecture

I’ve been writing increasingly complex firmware and am starting to notice that my knowledge of design patterns and architecture is a bit lacking. I’m trying to work on developing these skills and am hoping for some input. Note: this is for embedded c for microcontrollers.I’m working with a concept for a new project as an exercise right now that goes something like this:We have a battery management module with user I/OThe main controller is responsible for I/O (button, LCD, UART debug), detecting things like the charger being plugged in/unplugged, and managing high level ope...

 c                     1 answers                     85 view
 2018-10-22         Douglas

what reason can cause g_hash_table_steal to return false?

My program uses g_hash_table_steal to remove a key and its associated value from a GHashTable (libglib-2.0.so.0 RedHat 7.4). But it returns false. What reason can cause g_hash_table_steal to return false? A boolean can either be true or false. The documentation for g_hash_table_steal() says that it returns “true if the key was found and removed from the GHashTable”. So therefore it must return false if the key was not found in the GHashTable (so could not be removed). [XXX]

 c                     1 answers                     79 view
 2018-10-22         Rodney

PostMessage and CALLWNDHOOK, missing registered messages?

Here's the situation. I've got a two different window hooks, one's a global hook of the WH_SHELL variety that watches for new top-level windows, the second's a thread hook of the WH_CALLWNDPROC which is set on some of the top-level windows discovered by the first hook. The two hooks are implemented in different DLLs.As far as I can tell, both hooks are being installed properly. However, nothing I Post to the hooks windows with a message code > WM_USER a register message is ever handled by the custom WH_CALLWNDPROC hook, but "normal" windows messages are passing thought i...

 c                     2 answers                     92 view
 2018-10-22         Ansel

Can I get the SID("Oracle Session Id") through a OCI Function?

There is an example that simply uses a OCI function to execute a query.skip.. text *sql = (text *)"SELECT empno, ename FROM emp"; int id; text pad[4000]; strcpy(username, "scott"); strcpy(password, "tiger"); strcpy(dbname, "orcl"); OCIEnvCreate(&env, OCI_DEFAULT, 0, 0, 0, 0, 0, 0); OCIHandleAlloc(env, (dvoid *)&err, OCI_HTYPE_ERROR, 0, 0); if (r = OCILogon2(env, err, &svc, username, strlen(username), password, strlen(password), dbname, strlen(dbname), OCI_DEFAULT) != OCI_SUCCESS) { checkerr(err, "OCILogon2", r); } if (r = OCIStmtPrepare2(svc, (OCI...

 c                     1 answers                     51 view
 2018-10-22         Valentine

What is the best way to change to a currency format?

I have a list of values such as "12000","12345","123456" that need to be converted to currency ("120.00", "123.45", "1234.56"). The only way I know is to convert the value to a string, copy the first strlen()-2 characters to one string (dollars) and the remainging two digits to another string(cents) and then write them as the following:printf("%s.%s", dollars, cents); printf("$%.2f", value/100); [XXX]Don't use floats for storing or representing monetary amounts. Use longs (if you need more than 4 billion cent use llongs). Its usually a good idea to represent currency ...

 c                     3 answers                     10 view
 2018-10-22         Cecilia

Reading php.ini using zend for PHP extension (not PHP language)

I am trying to read some settings from php.ini using zend. The API that I am using islong zend_ini_long(char *name, uint name_length, int orig)But it always returns 0. I have double checked the name and also made sure that the value I am specifying in php.ini is greater then 0. Is there anything I am missing? long maxwait = zend_ini_long("max_execution_time", sizeof("max_execution_time"), 0);The problem is that ZEND_STRL is not returning the right length for the way that this API is intended to be used, so don't use it.I should add that most of the hash tables maint...

 c                     3 answers                     57 view
 2018-10-22         James

can't find assembly for pre-written functions

I am a huge fan of network protocols and libnet, which is why I've been trying to imitate some network protocols that are not included by libnet. Capturing packets, imitating headers etc works so far. Now I need a way to actually write these exact packets to my network card. I've tried libnet_adv_write_rawipv4() and -link(), both won't work. I can't cull the headers with libnet_adv_cull_header() because of the stupid errors and bugs. So I figured, that the problem could be solved with a little assembly: get the assembly code for the actual libnet_build() and libnet_write() ...

 c                     1 answers                     28 view

Page 2 of 2144  |  Show More Pages:  Top Prev Next Last