Every now and then, someone on SO points out that char (aka 'byte') isn't necessarily 8 bits.
It seems that 8-bit char is almost universal. I would have thought that for mainstream platforms, it is necessary to have an 8-bit char to ensure its viability in the marketplace.
Both now and historically, what platforms use a char that is no...
I apologize in advance for the long-winded question but I wanted to make sure I didn't leave out any key points that may alter your response.
I am responsible for maintaining system software written in 'C' of which we have a few common '.a' libraries. We have what I would call an "Execution Manager" who's main job is to fork and and ex...
How do I delete memory in C?
For example, I have:
#include<stdlib.h>
#include<stdio.h>
struct list_el {
int val;
struct list_el * next;
};
typedef struct list_el item;
void main() {
item * curr, * head;
int i;
head = NULL;
for(i=1;i<=10;i++) {
curr = (item *)malloc(sizeof(item));
curr->val = i;
...
hi, I am pretty new to C.
I am getting this error:
incompatible implicit declaration of built-in function ‘malloc’
Even when I fix the code based on the answers to include stdlib, I still get:
two or more data types in declaration specifiers
When trying to do this:
struct tnode
{
int data;
struct tnode * left;
...
I'm trying to use Visual Studio 2008 since I had problems opening a file in XCode. I am new to VS, but these are the steps I took. I created a new project, selected Win32 Console Application, empty project. My code is:
// C_test.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <stdlib.h>
int ...
I'm trying to allocate some memory for a char* as follows.
static ssize_t memo_write(struct file *filp, const char __user *buf,
size_t count, loff_t *f_pos){
ssize_t retval = -ENOMEM;
printk("write function\n");
if((data = kmalloc(strlen(buf), GFP_KERNEL)) == NULL)
printk("kmalloc fail\n");
if(copy_from_use...
The C language convention counts array indices from 0. Why do inode numbers start from 1 and not 0?
If inode 0 is reserved is for some special use, then what is the significance of inode 0?
...
Ritchie claims that file locking is not sufficient to prevent the confusion caused by programs such as editors that make a copy of a file while editing and then write the original file when done. Can you explain what he meant?
...
I want to design an algorithm for allocating and freeing memory pages and page tables. What data structures would allow best performance and simplest implementation?
...
I just wonder, can we execute a program on a machine without an operating system?
Besides, I heard that the Linux kernel is written in C language and a kernel is run during booting, so I just wonder how a computer understand the language without first compiling?
...
Is there a one line macro definition to determine the endianness of the machine. I am using the following code but converting it to macro would be too long.
unsigned char test_endian( void )
{
int test_var = 1;
unsigned char test_endian* = (unsigned char*)&test_var;
return (test_endian[0] == NULL);
}
...
Hello,
gcc 4.4.2 c89
I am trying to link some headers and libraries in my header file. But for some reason my program doesn't seem to link.
I have in my directory src/include/apr src/libs
I have compiled the libraries and placed them in my libs and I have put the headers in the include directory.
My executable is in the src director...
What is the difference between CreateThread and beginthread APIs in Windows? Which one is preferrable for thread creation?
...
Hi.
I've encountered problems with assembler code. I'm a newbie to assembler, so it seems difficult for me to solve it myself.
The task is: "To find minimal and maximal elements of the array."
All I've already done is searching for maximal element. I can't find out, how to make check for the minimal element and where I should put suc...
I want to compare side by side some C files with kdiff3 (the tool is what matters the less), but some parts have been "reformatted" in one of the files, thus giving false positives in the differences.
Kdiff3 allows you to run a preprocessor on the input files, and I thought that using "indent" (or similar tools like astyle or uncrustify...
I have a C++ application that calls SQLite's (SQLite is in C) sqlite3_exec() which in turn can call my callback function implemented in C++. SQLite is compiled into a static library.
If an exception escapes my callback will it propagate safely through the C code of SQLite to the C++ code calling sqlite3_exec()?
...
In C it's possible to write code before the first case label. Are there any cases for which it is useful to do this or is it just a 'dead block of code' ?
E.g.:
switch (...) {
{
int a = 0x2a;
printf("%d\n", a);
}
case 0:
...
}
...
Hello I have an unsigned char * that looks (after printf) like this (it's a SHA-1 hash):
n\374\363\327=\3103\231\361P'o]Db\251\360\316\203
I need to convert this unsigned char * to an unsigned int, what do you think it would be the best way to do it ? I have some ideas, but I'm not a C expert so wanted to see someone else ideas before...
To see what memory map regions a running program contains, I write a simple C program to read data from /proc/self/maps:
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
char buf[1024];
int fd;
ssize_t n;
fd = open("/proc/self/maps", O_RDONLY);
if (fd ...
On OpenSolaris ($^O eq 'solaris', vers. 2.11), I'm trying to build an XS module which uses the XPGv4v2/Single Unix Spec. understanding of struct msghdr, specifically for "ancillary data" interrogation.
However, the native perl (v5.8.4) was built without the requisite defines, and so the struct msghdr visible within my XS file is the old...