if I have
int a= 5;
long b= 10;
int count0 = 2;
void ** args0;
args0 = (void **)malloc(count0 * sizeof(void *));
args0[0] = (void *)&a;
args0[1] = (void *)&b;
how can I convert from args[0] and args0[1] ... |
|
First off, this is not a dupe of:
Is it safe to cast an int to void pointer and back to int again?
The difference in the questions is this: I'm only ... |
This question is almost a duplicate of some others I've found, but this specifically concerns POSIX, and a very common example in pthreads that I've encountered several times. I'm mostly concerned ... |
This situation occurs due to not using function prototypes. If you do, you will get an error and the build will fail. As it is, func() produces a warning that it is not defined and is assumed an extern returning an int. The linker sees func() as an unresolved function and it has func(int) available. In C, func() just means a ... |
On 18 Sep, 12:27, Chad How would you track the type infornation? why are you casting ... |
On 2008-01-03 13:10, Lars Uffmann wrote: Now we're getting to where it becomes interesting :) > James Kanze wrote: >>>int main(void) is better than int main() >>There is no difference. >As far as the compiler is concerned, no. As far as anyone who >reads the code is concerned, the first marks you as a C hacker, >who doesn't understand C++. > ... |
|
|
hlo, i've got a question , some people here gived me advice to use int main(),actually , i dont know what int main() is,but in my manual that i read ,the writer of the book says that i've got to use void main(). dont know what the problem is , help me! The difference is simple: 'void main()' is just plain ... |
Is that in the object line a conforming program? If so, why? If not, why? I'd expect it to be much like int main(void) { for (;;); } But if I compile it with lcc-win32 and run it in its rundos.exe, it says the program exits with a return value of -1073741819 (i.e. -2^30 + 5) after 0.032 seconds or so. ... |
I am using a global which is a void* I have it defined in one file as: void* hFlag; and one other header file as: extern void* hFlag; But I get this compile error: error C2040: 'hFlag' : 'void *' differs in levels of indirection from 'int' I can't understand what the problem is. I have another global variable which is ... |
In C++, you can NEVER use a void main(). It must always be int main(). in C++, returning a 1 inside main indicates that there was an error. A common occurrence of this is when you are trying to input from a file, but the file cannot be loaded. It correctly exits the program, but with the added note that there ... |
Martin Jrgensen Hi, I'm using this alloc_mem-function: - - - - - - - - - - - - - - - - - - - - - - - - void *alloc_mem (size_t num_elems, size_t elem_size, char *filename, int line, size_t *total_mem) { void *mem; size_t size = num_elems*elem_size; size += (sizeof (size_t) <= elem_size) ? elem_size : sizeof (size_t); ... |
I'm trying to portably define a type which is wide enough to hold an int, a wchar_t, or a void *. Here's what I've got: #include #include #include #if INT_MAX > INT32_MAX || WCHAR_MAX > INT32_MAX || \ INTPTR_MAX > INT32_MAX typedef int64_t funky_type; #elif INT_MAX > INT16_MAX || WCHAR_MAX > INT16_MAX || \ INTPTR_MAX > INT16_MAX typedef ... |
rahulsinner@gmail.com schrieb:[color=blue] > I have noticed everyone using "int main(void)".But doesnt the > standard pronounces it as > "int main(int argc,char *argv[])".And if i don't specify arguments,why > can't i simply put it as "int main()"[/color] See FAQ 11.12a. As it is usually better to make every function declaration a prototype, it is only consistent and sensible to do the same ... |
now suppose I have declared an integer value inside a function as int x; now if the return type of the function is of type (void *) then can I write return((void *)x) in side the function? I came across this in a document on multithreading in C..I can post the exact portion of code which works correctly with such an ... |
Thanks! I does not mean the prototype, but full function: I think the main function is only used only once in a .c file, so it does not need a pre-declare or something like that. Am I right? Thanks for your help! Should I use: #include int main() { .... return 0; } or this: #include int main(void) { ... |
main() is special. A program is not even required to work correctly (or compile or link) if main() does not return int. Or, more formally, an implementation (compiler, library, etc) is only required to support int main(). Other functions can have any return type the programmer might consider appropriate (int, void, pointers, double, struct types, enums, etc). |
Note, in unhosted environments like embedded systems (one's without a "typical" OS), the standard does not require int main, since there is no environment to return a value to. Thus, an embedded compiler may allow or even require void main, though personally I have not seen such an implementation. We occasionally see void main used on embedded projects here, though it's ... |
The first thing to understand is that void main() is NEVER right. It's more complex than this, as you will discover when learning more, but the core if it is that main() is called by the operating system as a function, just like you would call a function from inside your program... programs are really just functions that are run by ... |
|
Yeah, that looks a lot cleaner. Thanks for the pointer (hehe, I made a pun). I was getting a seg fault because it would fail to allocate nodes if the didn't exist, but I fixed it. Here's the completely working version: Code: void *write_vector(struct vector *v, int index, void *data) { struct data_node *cur_node; cur_node = v->data; /* Set the current ... |
23. void * -> int cboard.cprogramming.comCode: #include typedef struct { int index; int max; void **a; } list; list arraylist() { list alist; alist.a = malloc(10); alist.max = 10; alist.index = 0; return alist; } void add(list *l, void *obj) { if (l->index > l->max) realloc(&(l->a), l->max*2); l->max *= 2; l->a[l->index++] = obj; } void delete(list *l, int index) { l->a[index] = NULL; } void ... |
|
|
From http://www.faqs.org/faqs/C-faq/faq/ 11.12a: What's the correct declaration of main()? A: Either int main(), int main(void), or int main(int argc, char *argv[]) (with alternate spellings of argc and *argv[] obviously allowed). See also questions 11.12b to 11.15 below. References: ISO Sec. 5.1.2.2.1, Sec. G.5.1; H&S Sec. 20.1 p. 416; CT&P Sec. 3.10 pp. 50-51. 11.12b: Can I declare main() as void, to ... |
|
|
I read somewhere it is good etiquette to use int main().....I understand that 'argc' is the number of parameters handed to main(), and 'argv[]' is an array of char pointers to the parameters.......but am still a little confused. Am currently learning C, have written some pretty wicked programs, and about to send them in to be marked. All the example code ... |
You're working with raw memory, so use 'unsigned' instead. For speed, don't work with a char unless you have to-- use a long instead. Why copy 1 byte at a time, when you could copy 4? or more (depending on the native word-size of your processor)? Never modify your caller's pointers. Always work with a copy. Check for valid pointers, and ... |
Hi frequently I see mentioned the fact that we should use int main () and not void main().....the trouble here is that some of us here are doing a distance learning course in c programming....where the course provider frowns upon and deducts marks for using int main ()....unless we are passing a value back to the opsys. I personally use int ... |
Newbie question 2: hello again friendz of this forum. I'm learning c and I have got this doubt. I want to know why some people use int main() while some other people use void main(). I wonder which is better to use and why? Also why do we return 0 after a program? When 0 means false ? Shouldn't it return ... |
Just main() means whatever the compiler accepts for it's defaults, are used. A return of int may also be the default of the compiler. int main () with no return should give you an error "function should return a value..." void main() is an error with the newest standards, AFAIK, but not all compilers are up to that standard, yet. Old ... |