尝试打印Max& C中最小范围的Long Double偶然发现了不同格式说明符的问题,所以我尝试了以下代码中的每个建议:
#include<stdio.h>
#include<limits.h>
#include<float.h>
#include<math.h>
int main(void)
{
printf("Data Type Memory Size Range\n");
printf("------------------------------------------------------------- \n");
printf("long double %d bytes %Lf to %Lf |>(using %%Lf as format specifier)\n",sizeof(long double),LDBL_MIN,LDBL_MAX);
printf("long double %d bytes %lf to %lf |>(using %%lf as format specifier)\n",sizeof(long double),LDBL_MIN,LDBL_MAX);
printf("long double %d bytes %LG to %LG |> (using %%LG as format specifier)\n",sizeof(long double),LDBL_MIN,LDBL_MAX);
printf("long double %d bytes %E to %E |>(using %%E as format specifier)\n",sizeof(long double),LDBL_MIN,LDBL_MAX);
printf("long double %d bytes %e to %e |>(using %%e as format specifier)\n",sizeof(long double),LDBL_MIN,LDBL_MAX);
printf("long double %d bytes %llf to %llf |>(using %%llF as format specifier)\n",sizeof(long double),LDBL_MIN,LDBL_MAX);
printf("long double %d bytes %le to %le |>(using %%le as format specifier)\n",sizeof(long double),LDBL_MIN,LDBL_MAX);
printf("long double %d bytes %f to %f |>(using %%f as format specifier)\n",sizeof(long double),LDBL_MIN,LDBL_MAX);
printf("-------------------------------------------------------------\n");
printf("NOTE: I'm trying to find the range of long double!\n");
printf(" But none of the format specifiers seems to work! Please Help...\n");
return 0;
}
根据https://www.tutorialspoint.com/cprogramming/c_data_types.htm
long double的内存大小:10个字节(我知道这可能会有所不同)
长双倍范围:3.4E-4932至1.1E + 4932
*但是我的代码输出在3.4E-4932到1.1E + 4932附近没有。但为什么?
答案 0 :(得分:1)
编译器警告未完全启用。
许多编译器指出printf()
说明符不匹配
说明符与long double
和size_t
(sizeof
的返回类型)@melpomene
L
指定以下a
,A
,e
,E
,f
,F
,{{ 1}}或g
转换规范适用于G
参数。 C11dr§7.21.6.17
long double
答案 1 :(得分:0)
开始
https://gcc.gnu.org/onlinedocs/libquadmath/#toc-GNU-Free-Documentation-License-1
CC=gcc
CFLAGS=-lm -ll -lquadmath -mlong-double-128
DEPS =
OBJ = sizeof.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
sizeof: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS)