logo
down
shadow

sizeof() showing different output


sizeof() showing different output

Content Index :

sizeof() showing different output
Tag : c , By : druta
Date : November 29 2020, 01:01 AM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

What is the sizeof(main), sizeof(printf), sizeof(scanf)?


Tag : c , By : SachinJadhav
Date : March 29 2020, 07:55 AM
this one helps. In the gcc compiler, sizeof(main), sizeof(printf) and sizeof(scanf) all are 1. I want to know how the size of all these are 1. What is the logic behind it? , Because the C(99) standard requires (ยง6.5.3.4/1)
sizeof(&main)
sizeof(&printf)
sizeof(&scanf)
4187     if (type_code == FUNCTION_TYPE)
4188       {
4189         if (is_sizeof)
4190           {
4191             if (complain && (pedantic || warn_pointer_arith))
4192               pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
4193                        "invalid application of %<sizeof%> to a function type");
4194             else if (!complain)
4195               return error_mark_node;
4196             value = size_one_node;
4197           }
4198         else
4199           value = size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
4200       }
4201     else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
4202       {
4203         if (type_code == VOID_TYPE
4204             && complain && (pedantic || warn_pointer_arith))
4205           pedwarn (loc, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
4206                    "invalid application of %qs to a void type", op_name);
4207         else if (!complain)
4208           return error_mark_node;
4209         value = size_one_node;
4210       } 

C/C++: sizeof(short), sizeof(int), sizeof(long), sizeof(long long), etc... on a 32-bit machine versus on a 64-bit machin


Tag : cpp , By : PPD
Date : March 29 2020, 07:55 AM
This might help you Looks right to me. In c/c++ int isn't specifically defined in terms of bit-size. When creating a project you can select a "console application". VS2012 still supports C, but they mostly lump projects into C/C++. There is a compiler option (/TC I think) which will force the compiler into C compliance. By default it will imply the language by the file extension. MS C support isn't ideal, it doesn't include stdbool.h for instance.
If you want to control the bit size of your data you can use stdint.h which contains exact width int datatypes.

sizeof not showing the expected output


Tag : c , By : markku
Date : March 29 2020, 07:55 AM

Where in the C++ Standard does it say that sizeof(wchar_t) <= sizeof(long) and sizeof(bool) <= sizeof(long)?


Tag : cpp , By : brennen
Date : March 29 2020, 07:55 AM

Marshal.SizeOf of a structure showing wrong output


Tag : chash , By : Hans-Inge
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , It's showing 8 because of structure member alignment rules.
If you want to set your struct as unaligned, you need to use StructLayout with the Pack = 1 attribute like so:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct abc
{
    short a;
    byte b;
    int c;
}
Related Posts Related QUESTIONS :
  • I have some question about how to save generated data in a for looping in a new string
  • How to declare a global dynamic array with C/OpenACC with PGI compiler
  • Qsort() doesn't work on a struct
  • Cant free info_ptr in libpng
  • I don't understand why I'm definitely losing blocks of memory
  • ATMEGA328p convert analog value to voltage
  • how to use audit in linux to monitor a file using libaudit
  • Is there a way to find the position of a special character '\n' in a file in C?
  • Array is printing with weird question mark symbols when printing fibonacci sequences
  • Self provoked buffer overflow in C
  • Why my code refuse to compare the generated hashes
  • Makefile No such file or directory
  • Why is pthread_equal threadsafe?
  • Is there a way I can shorten this if statment?
  • fscanf() != EOF as exit condition of loop exits at the wrong time
  • I made a stack using linked list (without array), but my pop function is not working
  • How can I start with this problem and fix my code?
  • How to identify which file implicitly relies on linkage with a library?
  • Does a stray \ [backslash] have any meaning in C code?
  • strtok returns NULL despite not having reached the end of the string
  • Is 0x9B (155decimal) a special control character? Why is it missing from ascii tables?
  • windows C system call with spaces in command
  • FFmpeg C API documentation/tutorial
  • Thread scheduling Round Robin / scheduling dispatch
  • Define integer ranges in C
  • feof() in C file handling
  • How to check for signed integer overflow in C without undefined behaviour?
  • Display processes that access a folder
  • How to printf a time_t variable as a floating point number?
  • Parenthesis operator in C. What is the effect in the following code
  • Is there table with timing(cost) of C functions?
  • How can I access a global pointer outside of a C function?
  • Are fopen/fread/fgets PID-safe in C?
  • How can multiple variables be passed to a function cleanly in C?
  • How to use pthread_atfork() and pthread_once() to reinitialize mutexes in child processes
  • Find function call in a list of binaries
  • How to return a single variable from a CUDA kernel function?
  • How to get number of cores in Win32?
  • Handling aces and finding a segfault in a blackjack program
  • function prototype declarations
  • How to convert from Hex to Decimal using only Integers in C
  • How to parse from char array using yacc?
  • I can not work with linked list inside linked list
  • Finding the index of largest number
  • Decompose a number to product of prime numbers and print it like 18=2*3^2
  • programming EXACT timer which calles a function in c language every x seconds
  • Combining macros generate errors
  • Why am I not getting error when I store values of different types in an array in C language?
  • What is the purpose of the base case dp[0] = -1 of this DP array in the palindromic partitions problem?
  • Having function choose largest number of given ones
  • Data structures layout
  • How to retrieve probuf from C library
  • Printf float number in hexadecimal format returns random vlaue
  • Memory allocation in C from 1 to N
  • Emit signal from separate thread in glib/gtk
  • How to fix Valgrind "Conditional Jump..." error
  • The text to be printed is being printed on the command line rather than print space while using fork on terminal
  • Deleting an element from an array of structures
  • How to read time stamp data from text file using C code?
  • I can't understand this code? Is it normal or I'm not ready?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com