Sponsored Content
Top Forums Programming sizeof an array of structure without using 'sizeof' operator Post 302302303 by Corona688 on Monday 30th of March 2009 03:49:00 PM
Old 03-30-2009
Cast it into an unsigned long instead. unsigned int will truncate a pointer on a lot of architectures.
 

10 More Discussions You Might Find Interesting

1. Programming

sizeof

we know that sizeof never returns zero when used with structure then why in this case it is returning zero struct foo { char c; }; void main() { struct foo f; cout<<sizeof(f); } i am working on solaris 5.8 isn't the above function should return the size of empty structure (7 Replies)
Discussion started by: ramneek
7 Replies

2. Programming

Search attributes in one structure using the values from another structure

Hello Groups I am trying to find out ways of comparing a value from a 'c' structure to a value in another 'C' structure. the 'C' structure can be a List or liked list as it contains lot many records. if we loop it in both the structures it is going to consume time. I am looking for a simple... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

3. Programming

Problem in static structure array in C

Hi, I have a following problem in C. I have a function A in which I used to call another function (function B) and pass an array of values through array variable by using below:- foo=functionB(array); In functionB, i used to just return some "values" (e.g return num;) in order to pass... (1 Reply)
Discussion started by: ahjiefreak
1 Replies

4. Programming

How to get the sizeof char pointer

The below code throws the error, since the size of x = 19 is not passed to the cstrCopy function. using namespace std; static void cstrCopy(char *x, const char*y); int main () { char x; const string y = "UNIX FORUM"; cstrCopy(x,y.c_str()); return 0; } void cstrCopy(char *x,... (3 Replies)
Discussion started by: SamRoj
3 Replies

5. Programming

Doubts regarding sizeof() operator

Hi, There are some bewildering sizeof() questions I have in my mind. Could anyone shed some light on this? int main() { printf("%d\n", sizeof(main)); // Ans: 1 } That is, the sizeof() a function identifier though it is treated internally as a pointer gives 1 byte always, why? ... (5 Replies)
Discussion started by: royalibrahim
5 Replies

6. Programming

sizeof(object) in C++

Hi, I have defined the class and call the sizeof(object to class) to get the size. # include <iostream> # include <iomanip> using namespace std; class sample { private: int i; float j; char k; public: sample() { } (2 Replies)
Discussion started by: ramkrix
2 Replies

7. Programming

structure pointer array as function parameters

if i create an array of pointers to a structure "struct node" as: struct node *r; and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as: r=multiplty(.......) /*some parameters*/ is... (2 Replies)
Discussion started by: mscoder
2 Replies

8. Programming

C Data Structure to represent a Sparse Array

Which data structure will be most appropriate to represent a sparse array? (1 Reply)
Discussion started by: rupeshkp728
1 Replies

9. Shell Programming and Scripting

Sizeof a file from directory path in perl

Hai how to find size of a file?? ex : /home/kiran/pdk/sample/calibre this is a path In that I have to find size of a files in side a calibre(it is the folder) like .results or .summary (1 Reply)
Discussion started by: kiran425
1 Replies

10. Programming

Compiler/Runtime uses of sizeof

Ignoring other considerations for a moment and in general ... Would there be a difference in result (dot oh or execution) of: A. strncpy( a, b, sizeof(a) ); vs. B. c = sizeof(a); strncpy( a, b, c ); My general understanding is (at least I think my understanding is) that... (10 Replies)
Discussion started by: GSalisbury
10 Replies
ATOMIC_CAS(3)						   BSD Library Functions Manual 					     ATOMIC_CAS(3)

NAME
atomic_cas, atomic_cas_32, atomic_cas_uint, atomic_cas_ulong, atomic_cas_ptr, atomic_cas_64, atomic_cas_32_ni, atomic_cas_uint_ni, atomic_cas_ulong_ni, atomic_cas_ptr_ni, atomic_cas_64_ni -- atomic compare-and-swap operations SYNOPSIS
#include <sys/atomic.h> uint32_t atomic_cas_32(volatile uint32_t *ptr, uint32_t old, uint32_t new); unsigned int atomic_cas_uint(volatile unsigned int *ptr, unsigned int old, unsigned int new); unsigned long atomic_cas_ulong(volatile unsigned long *ptr, unsigned long old, unsigned long new); void * atomic_cas_ptr(volatile void *ptr, void *old, void *new); uint64_t atomic_cas_64(volatile uint64_t *ptr, uint64_t old, uint64_t new); uint32_t atomic_cas_32_ni(volatile uint32_t *ptr, uint32_t old, uint32_t new); unsigned int atomic_cas_uint_ni(volatile unsigned int *ptr, unsigned int old, unsigned int new); unsigned long atomic_cas_ulong_ni(volatile unsigned long *ptr, unsigned long old, unsigned long new); void * atomic_cas_ptr_ni(volatile void *ptr, void *old, void *new); uint64_t atomic_cas_64_ni(volatile uint64_t *ptr, uint64_t old, uint64_t new); DESCRIPTION
The atomic_cas family of functions perform a compare-and-swap operation in an atomic fashion. The value of the variable referenced by ptr is compared against old. If the values are equal, new is stored in the variable referenced by ptr. The old value of the variable referenced by ptr is always returned regardless of whether or not the new value was stored. Applications can test for success of the operation by comparing the return value to the value passed as old; if they are equal then the new value was stored. The non-interlocked variants, *_ni(), guarantee atomicity within the same CPU with respect to interrupts and preemption. For example, they are suitable for synchronizing compare-and-swap operations on a variable shared by a thread and an interrupt that are bound to the same CPU. The *_ni() variants are not atomic with respect to different CPUs. *_ni() variants should avoid the interprocessor synchronization overhead of the standard compare-and-swap operations. The 64-bit variants of these functions are available only on platforms that can support atomic 64-bit memory access. Applications can check for the availability of 64-bit atomic memory operations by testing if the pre-processor macro __HAVE_ATOMIC64_OPS is defined. SEE ALSO
atomic_ops(3) HISTORY
The atomic_cas functions first appeared in NetBSD 5.0. NOTES
On some architectures, a *_ni() variant is merely an alias for the corresponding standard compare-and-swap operation. While the non-inter- locked variant behaves correctly on those architectures, it does not avoid the interprocessor synchronization overhead. BSD
February 11, 2010 BSD
All times are GMT -4. The time now is 12:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy