#include <stdio.h>
int main() {
unsigned long long int num = 285212672; //FYI: fits in 29 bits
int normalInt = 5;
printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
My number is 8 bytes wide and its value is 285212672l. A normal number is 0.
Run Code Online (Sandbox Code Playgroud)
我认为这个意想不到的结果是来自打印unsigned long long int.你怎么printf()了unsigned long long int?
我在这里读到在Objective-C之前学习C?
通常我会用纯C代码替换一些Obj-C代码(毕竟你可以根据需要混合它们,Obj-C方法的内容可以完全是纯C代码)
这是真的?
是否有可能纯粹使用C编程语言构建iPhone应用程序?
下面是两个几乎相同的程序,除了我切换i和j变量.它们都运行在不同的时间.有人能解释为什么会这样吗?
版本1
#include <stdio.h>
#include <stdlib.h>
main () {
int i,j;
static int x[4000][4000];
for (i = 0; i < 4000; i++) {
for (j = 0; j < 4000; j++) {
x[j][i] = i + j; }
}
}
Run Code Online (Sandbox Code Playgroud)
版本2
#include <stdio.h>
#include <stdlib.h>
main () {
int i,j;
static int x[4000][4000];
for (j = 0; j < 4000; j++) {
for (i = 0; i < 4000; i++) {
x[j][i] = i …Run Code Online (Sandbox Code Playgroud) 我从网上从https://computing.llnl.gov/tutorials/pthreads/上摘下了以下演示
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5
void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0; t<NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
pthread_exit(NULL);
}
Run Code Online (Sandbox Code Playgroud)
但是当我在我的机器上编译它(运行Ubuntu Linux 9.04)时,我收到以下错误:
corey@ubuntu:~/demo$ gcc -o term term.c …Run Code Online (Sandbox Code Playgroud) 我知道这是一个非常基本的问题,但是我在用高级语言编写一些项目之后开始使用一些基本的C++编程.
基本上我有三个问题:
怎么做到这一点?
如果我想分析如何编译某些内容,我将如何获得发出的汇编代码?
似乎很清楚它应该设置.
__attribute__功能吗?一个宏?句法?__attribute__((destructor))跑?__attribute__((constructor))
static void initialize_navigationBarImages() {
navigationBarImages = [[NSMutableDictionary alloc] init];
}
__attribute__((destructor))
static void destroy_navigationBarImages() {
[navigationBarImages release];
}
Run Code Online (Sandbox Code Playgroud) 假设我有一个带有可变数量参数的C函数:如何调用另一个函数,该函数需要从其内部获取可变数量的参数,并将所有参数传递到第一个函数中?
例:
void format_string(char *fmt, ...);
void debug_print(int dbg_lvl, char *fmt, ...) {
format_string(fmt, /* how do I pass all the arguments from '...'? */);
fprintf(stdout, fmt);
}
Run Code Online (Sandbox Code Playgroud) c ×10
c++ ×5
gcc ×3
objective-c ×2
pointers ×2
arrays ×1
assembly ×1
cocoa-touch ×1
cpu-cache ×1
debugging ×1
for-loop ×1
ios ×1
linux ×1
long-long ×1
optimization ×1
performance ×1
printf ×1
pthreads ×1
syntax ×1