c

thread_fork working on kernel

a 夏天 提交于 2021-02-17 06:05:13
问题 I am working on OS161 where C pthread library is not primarily supported. My current objective is to understand the sys calls and make some simple programs run. my simple function has following code: int id = 1; long id2 = 1; int ret = thread_fork("myThread", (void *)id, id2, void (*function)((void *)id, id2), NULL); kprintf("\nHello World\n"); return; ` where call to thread_fork is int thread_fork(const char *name, void *data1, unsigned long data2, void (*func)(void *, unsigned long), struct

How to print Address of a method in c#?

安稳与你 提交于 2021-02-17 06:01:21
问题 In C Programming, void foo() { } void main() { printf("%p",foo); } will print the address of foo function. Please let me know if there is a way in C# to achieve the same. 回答1: C# is a high-level language. A method does not need to have an "address" -- this is an implementation detail left to the runtime. However, if you need to interface with C code that requires a method address (for example, to provide a callback to a Windows API method), you can create a delegate and retrieve a function

C: Fastest way to determine, if any key on the keyboard has been pressed

梦想与她 提交于 2021-02-17 05:56:38
问题 I am searching for the fastest possible way in C to determine if any key on the keyboard has been pressed. I am not looking for how to determine if a specific key is pressed (in that case, GetAsyncKeyState() would work). Also, it needs to work in the background, so without the program window having focus (the program will be running in the background). EDIT: The program will react on every keypress with a sound output. I want it to output a sound everytime I type something (like in Word and

Cache block tag size

自作多情 提交于 2021-02-17 05:54:06
问题 I'm writing a cache simulation program in C on linux using gcc as the compiler and I'm done for the most part. Only a few test cases go wrong (a few things out of the thousands of fed addresses that should be hitting are missing). I specify the cache properties on the command line. I suspect the error within my code has to do with the tag (if things aren't hitting then their tags aren't matching up when they should be). So my question is: Am I calculating the tag right? //setting sizes of

Can not read text file in C

荒凉一梦 提交于 2021-02-17 05:36:33
问题 I have an assignment to create a menu program that uses a linked list to store a list of phone catalog. Here is my source code: int isempty(FILE *in) { return in == NULL; } node *makenewnode(item newitem) { node *newnode = (node *) malloc(sizeof(node)); newnode->info = newitem; return newnode; } int countlines(FILE *datain) { int lines = 0; char string[MAX]; while (fgets(string, MAX, datain)) lines++; return lines; } node *push(node *listin, item newitem) { node *newnode = makenewnode(newitem

Can not read text file in C

守給你的承諾、 提交于 2021-02-17 05:36:05
问题 I have an assignment to create a menu program that uses a linked list to store a list of phone catalog. Here is my source code: int isempty(FILE *in) { return in == NULL; } node *makenewnode(item newitem) { node *newnode = (node *) malloc(sizeof(node)); newnode->info = newitem; return newnode; } int countlines(FILE *datain) { int lines = 0; char string[MAX]; while (fgets(string, MAX, datain)) lines++; return lines; } node *push(node *listin, item newitem) { node *newnode = makenewnode(newitem

Is empty array in the end of the structure a C standard?

梦想与她 提交于 2021-02-17 05:25:19
问题 I have noticed that an empty array in the end of the structure is often used in open source projects: typedef struct A { ...... void *arr[]; } A; I want to know is this a C standard? Or only OK for gcc compiler? 回答1: As of C99, it is now a C standard. Pre-C99 compilers may not support it. The old approach was to declare a 1-element array, and to adjust the allocation size for that. New way: typedef struct A { ...... void *arr[]; } A; int slots = 3; A* myA = malloc(sizeof(A) + slots*sizeof

Using fgets() right after getchar()

ⅰ亾dé卋堺 提交于 2021-02-17 05:21:39
问题 void read_stdin(trace_t* trace, state_t state, action_t** action_list) { // initial stage int c; while ((c = getchar())!= EOF && c!='#') { if (my_isalpha(c)==LOWERCASE) { state[c-ASCII_CODE_LOWER_A] = '1'; } } printf("%s\n", state); char str[2]; fgets(str, 2, stdin); printf("%s", str); } If '#' is the last character I enter in the getchar() loop, fgets() records the newline character from when I press enter and skips to the print statement immediately (which prints the '\n') I could fix this

Inline assembly statements in C code and extended ASM for ARM Cortex architectures

你。 提交于 2021-02-17 05:18:30
问题 I am trying to compile the following two pieces of code with ARM Compiler 5 for a Cortex A microprocessor: Part 1 : static inline void cp15_write_sctlr(uint32_t value) { asm("mcr p15, 0, %0, c1, c0, 0" :: "r"(value)); } static inline uint32_t cp15_read_actlr(void) { uint32_t actlr; asm("mrc p15, 0, %0, c1, c0, 1" : "=r"(actlr)); return actlr; } Part 2 : static inline void dmb(void) { asm("dmb" ::: "memory"); } static inline void dsb(void) { asm("dsb" ::: "memory"); } static inline void isb

send arbitrary ethernet frames using packet_mmap but can't set up ring

梦想的初衷 提交于 2021-02-17 05:16:13
问题 I am trying to send raw ethernet frames using packet_mmap. A good example I found is at this gist. However, this example was using link-level raw socket, so the source ethernet address of ethernet frames sent is fixed to be the address of the interface. What I need is to be able to send an arbitrary ethernet frames (the source ethernet address can be arbitrary). So I adopt the gist a little bit by changing fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); to be fd = socket(AF_INET,SOCK