标签: c

什么是阵列衰减?

什么是阵列的衰变?与数组指针有关系吗?

c c++ arrays pointers

358
推荐指数
8
解决办法
5万
查看次数

如何使用printf格式化unsigned long long int?

#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

c syntax printf format-specifiers long-long

356
推荐指数
8
解决办法
73万
查看次数

如何在C中纯粹编写iOS应用程序

我在这里读到在Objective-C之前学习C?

通常我会用纯C代码替换一些Obj-C代码(毕竟你可以根据需要混合它们,Obj-C方法的内容可以完全是纯C代码)

这是真的?

是否有可能纯粹使用C编程语言构建iPhone应用程序?

c cocoa-touch objective-c objective-c-runtime ios

352
推荐指数
3
解决办法
8万
查看次数

在迭代2D数组时,为什么循环的顺序会影响性能?

可能重复:
这两个for循环中的哪一个在时间和缓存性能方面更有效

下面是两个几乎相同的程序,除了我切换ij变量.它们都运行在不同的时间.有人能解释为什么会这样吗?

版本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)

c optimization performance for-loop cpu-cache

350
推荐指数
6
解决办法
4万
查看次数

Linux中对pthread_create的未定义引用

我从网上从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 linux multithreading pthreads

349
推荐指数
9
解决办法
57万
查看次数

为什么要使用指针?

我知道这是一个非常基本的问题,但是我在用高级语言编写一些项目之后开始使用一些基本的C++编程.

基本上我有三个问题:

  1. 为什么使用指针超过正常变量?
  2. 我应该何时何地使用指针?
  3. 你如何使用指针与数组?

c c++ pointers

344
推荐指数
14
解决办法
23万
查看次数

344
推荐指数
8
解决办法
156万
查看次数

你如何在gcc中从C/C++源获得汇编程序输出?

怎么做到这一点?

如果我想分析如何编译某些内容,我将如何获得发出的汇编代码?

c c++ debugging assembly gcc

340
推荐指数
14
解决办法
31万
查看次数

__attribute __((构造函数))究竟是如何工作的?

似乎很清楚它应该设置.

  1. 什么时候它运行?
  2. 为什么有两个括号?
  3. __attribute__功能吗?一个宏?句法?
  4. 这在C中有用吗?C++?
  5. 它的工作功能是否需要是静态的?
  6. 什么时候__attribute__((destructor))跑?

目标C中的示例:

__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 c++ gcc objective-c

327
推荐指数
4
解决办法
12万
查看次数

传递可变数量的参数

假设我有一个带有可变数量参数的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 variadic-functions

325
推荐指数
7
解决办法
17万
查看次数